Is it possible to use the
Enterprise Library 4.1 TraceListeners without using the entire
Enterprise Library Logging AB? I'd prefer to simply use .NET Diagnostics Tracing, but would like to setup a listener that sends emails on Error events. I figured I could use the
Enterprise Library EmailTraceListener. However, my initial attempts to configure it have failed. Here's what I hoped would work:
<system.diagnostics>
<trace autoflush="false" />
<sources>
<source name="SampleSource" switchValue="Verbose" >
<listeners>
<add name="textFileListener" />
<add name="emailListener" />
</listeners>
</source>
</sources>
<sharedListeners>
<add name="textFileListener" type="System.Diagnostics.TextWriterTraceListener" initializeData="..\trace.log" traceOutputOptions="DateTime">
<filter type="System.Diagnostics.EventTypeFilter" initializeData="Verbose" />
</add>
<add name="emailListener" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.EmailTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging" toAddress="
[email protected]" fromAddress="
[email protected]" smtpServer="mail.example.com" >
<filter type="System.Diagnostics.EventTypeFilter" initializeData="Verbose" />
</add>
</sharedListeners>
</system.diagnostics>
However I get
[ArgumentException: The parameter 'address' cannot be an empty string.
Parameter name: address]
System.Net.Mail.MailAddress..ctor(String address, String displayName, Encoding displayNameEncoding) +1098157
System.Net.Mail.MailAddress..ctor(String address) +8
Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.EmailMessage.CreateMailMessage() +256
Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.EmailMessage.Send() +39
Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.EmailTraceListener.Write(String message) +96
System.Diagnostics.TraceListener.WriteHeader(String source, TraceEventType eventType, Int32 id) +184
System.Diagnostics.TraceListener.TraceEvent(TraceEventCache eventCache, String source, TraceEventType eventType, Int32 id, String format, Object[] args) +63
System.Diagnostics.TraceSource.TraceEvent(TraceEventType eventType, Int32 id, String format, Object[] args) +198
System.Diagnostics.TraceSource.TraceInformation(String message) +14
Which leads me to believe the .NET Tracing code does not care about the "non-standard" config attributes I've supplied for emailListener. I also tried adding the appropriate LAB configSection declaration and:
<loggingConfiguration>
<listeners>
<add toAddress="
[email protected]" fromAddress="
[email protected]" smtpServer="mail.example.com" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.EmailTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging" name="emailListener" />
</listeners>
</loggingConfiguration>
This also results in the same exception. I figure it's possible to programmatically configure the EmailTraceListener, but I prefer this to be config-driven. I also understand I can implement my own derivative of TraceListener.
So, is it possible to use the Ent Lib TraceListeners, without using the whole Ent Lib LAB,
and configure them from the config file?
Update: After examining the code, I have discovered it is not possible. The Ent Lib TraceListeners do not actually utilize the config attributes they specify in overriding TraceListener.GetSupportedAttributes(), despite the recommendations in the .NET TraceListener documentation. Bug filed.