Microsoft.Practices.EnterpriseLibrary.Logging Multiple names in ToAddress

Topics: Logging Application Block
Sep 22, 2009 at 9:42 AM
Edited Sep 22, 2009 at 9:43 AM

Hi - I am using Microsoft.Practices.EnterpriseLibrary.Logging Email TracceListener however I have only been able to add a single address in the ToAddress property. Adding additional email address's delimiting with either , or ; does not work. Only the first email address receives the message.

Does anyone know what the delimiter should be ir how to include additional email addresses in the ToAddress?

Note the the below works fine.

<listeners>

<add toAddress="janedoe@somewhere.com" fromAddress="johndoe@somewhere.com" subjectLineStarter="Please see.." subjectLineEnder="Error in RC"  smtpServer="SMTPGW" smtpPort="50" formatter="Text Formatter" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.EmailTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"  traceOutputOptions="None" filter="All" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.EmailTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" name="Email TraceListener" />

However this does not, only Jane receives the message:

<listeners>

<add toAddress="janedoe@somewhere.com, anotherdoes@somewhere.com"  fromAddress="johndoe@somewhere.com"  subjectLineStarter="Please see.." subjectLineEnder="Error in RC"  smtpServer="SMTPGW" smtpPort="50" formatter="Text Formatter" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.EmailTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"  traceOutputOptions="None" filter="All" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.EmailTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"  name="Email TraceListener" />

Thanks in advance

Lisa

Sep 22, 2009 at 10:08 AM

Hi,

I looked at the source code, and it splits the email addresses using ; (semicolon). You've said that you've tried using the semi colon as delimiter but only the first email address recieves the log. Can you please try it again using the semi colon delimiter and a different second email address.

Valiant Dudan
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com

Sep 22, 2009 at 10:53 AM

Hi Valiant - thanks for the quick response. Apologies, you are correct, splitting via ; works.

Thanks,

Lisa

Sep 24, 2009 at 7:39 PM
Edited Sep 24, 2009 at 9:12 PM

hi,

i'm looking for a way to set adresses dynamically by code. is this possible?

i read the thread about switching email subjects here (http://entlib.codeplex.com/Thread/View.aspx?ThreadId=66428). is this also the only way for my purpose?

Sep 25, 2009 at 5:49 AM

Actually, that thread discusses a way to make the Subject of the emailtracelistener configurable in the Entlib config tool.  You can try this code:

ExeConfigurationFileMap fileMap = new ExeConfigurationFileMap();
fileMap.ExeConfigFilename = "app.exe.config";
Configuration entLibConfig = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None);
LoggingSettings loggingSettings = (LoggingSettings)entLibConfig.GetSection(LoggingSettings.SectionName);

EmailTraceListenerData emailTraceListener = loggingSettings.TraceListeners.Get("Email TraceListener") as EmailTraceListenerData;
emailTraceListener.ToAddress = "helloworld@google.com";
entLibConfig.Save();

Take note that there is a slight delay when updates are made to a configuration during runtime.  I believe the default is 15 seconds.

 

Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com

Sep 25, 2009 at 9:06 AM
AvanadeSupport wrote:

Actually, that thread discusses a way to make the Subject of the emailtracelistener configurable in the Entlib config tool.  You can try this code:

ExeConfigurationFileMap fileMap = new ExeConfigurationFileMap();
fileMap.ExeConfigFilename = "app.exe.config";
Configuration entLibConfig = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None);
LoggingSettings loggingSettings = (LoggingSettings)entLibConfig.GetSection(LoggingSettings.SectionName);

EmailTraceListenerData emailTraceListener = loggingSettings.TraceListeners.Get("Email TraceListener") as EmailTraceListenerData;
emailTraceListener.ToAddress = "helloworld@google.com";
entLibConfig.Save();

Take note that there is a slight delay when updates are made to a configuration during runtime.  I believe the default is 15 seconds.

 

Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com

thanks!

in consideration of this answer and the one in this thread http://entlib.codeplex.com/Thread/View.aspx?ThreadId=68637 i assume that there are just 2 ways for dynamic changes like changing log file destination in a flat file trace listner or changing the ToAddress attribute of an email trace listener:

  • change config files like the way above
  • create new logwriter factorys in code

right? is there no way to do this by parameter of the logger like 'logger.emailtracelister.toaddresse = admin@example.com' because in most cases i want to use default values. is there something similiar to my example in the queue for entlib 5? the thing is, that both solutions have a moldy aftertaste:

  • it's bad for performance to edit config files (especially if you would have to wait 15 seconds...)
  • creating your own factories in code annul the intention of global configuration and it's not an accurate way to be used in more or less big applications

 

 

 

 

 

 

 

Sep 25, 2009 at 10:19 AM

Yes, those are the possible ways.  By the way, you can modify the 15 seconds delay by modifying the source code. (http://entlib.codeplex.com/Thread/View.aspx?ThreadId=70014)

I don't think there'd be any additional feature for that in Entlib 5. 

 

Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com