Logging fails when source attribute value changes for Event Log Destination

Topics: Logging Application Block
Dec 9, 2009 at 9:19 PM

Hi,

I am trying to log event information to both system Event Log and a text file using Enterprise library 3.1 Logging Application Block in an ASP.NET Web Service application.
Here is the working code and the configuration.

================================================================

LogEntry logEntry = new LogEntry();

logEntry.Categories.Clear();
logEntry.Categories.Add("Troubleshooting");
logEntry.Priority = 5;
logEntry.Severity = TraceEventType.Error;

Dictionary<string, object> dictionary = new Dictionary<string, object>();

dictionary.Add("Email Date", emailDate);
dictionary.Add("Sender's Email", sendersEmail);
dictionary.Add("Subject", subject);
dictionary.Add("Body", body);

logEntry.Message = exceptionMessage;

logEntry.ExtendedProperties = dictionary;

Logger.Write(logEntry);


================================================================

Working configuration.

================================================================

<loggingConfiguration name="Logging Application Block" tracingEnabled="true" defaultCategory="General" logWarningsWhenNoCategoriesMatch="true">
<listeners>
<add name="Event Log Destination"
    type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FormattedEventLogTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging"
    listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FormattedEventLogTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging"
    source ="Test Logging Block"
    formatter="Text Formatter"
    machineName="."
    />
<add name="Flat File Destination"
 type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging"
 listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging"
 fileName ="C:\Documents and Settings\All Users\LogFiles\ClickShared\trace.log"
 header="----------------header------------------------"
 footer="----------------footer------------------------"
 formatter="Text Formatter"
    />
</listeners>
<formatters>
<add template="Timestamp: {timestamp}&#xD;&#xA;Message: {message}&#xD;&#xA;Category: {category}&#xD;&#xA;Priority: {priority}&#xD;&#xA;EventId: {eventid}&#xD;&#xA;Severity: {severity}&#xD;&#xA;Title:{title}&#xD;&#xA;Machine: {machine}&#xD;&#xA;Application Domain: {appDomain}&#xD;&#xA;Process Id: {processId}&#xD;&#xA;Process Name: {processName}&#xD;&#xA;Win32 Thread Id: {win32ThreadId}&#xD;&#xA;Thread Name: {threadName}&#xD;&#xA;Extended Properties: {dictionary({key} - {value}&#xD;&#xA;)}"
  type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
  name="Text Formatter" />
    </formatters>
    <categorySources>
<add switchValue="All" name="Troubleshooting">
  <listeners>
    <add name="Event Log Destination" />
    <add name="Flat File Destination" />
  </listeners>
</add>
    </categorySources>
    <specialSources>
<allEvents switchValue="All" name="All Events" />
<notProcessed switchValue="All" name="Unprocessed Category" />
<errors switchValue="All" name="Logging Errors &amp; Warnings">
  <listeners>
    <add name="Event Log Destination" />
    <add name="Flat File Destination" />
  </listeners>
</errors>
    </specialSources>
  </loggingConfiguration>
================================================================

If I change the source attribute value for the Event Log Destination, the code fails. No exception is generated but no information is logged.

Really appreciate if someone could shed light on what I am doing wrong.

Thanks,
dnfan

Dec 10, 2009 at 6:09 AM

Hi,

I tried running your code and configuration. It does not reproduce the error that you're describing. I still get logs to both destinations. Is this your default configuration? Then if you just change the "Source", you'll never get the log?

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

Dec 11, 2009 at 1:03 AM

Thank for your response.

Correct. 

If I change the source attribute value in the following section in the config file:

<add name="Event Log Destination"
    type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FormattedEventLogTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging"
    listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FormattedEventLogTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging"
    source ="Test Logging Block"
    formatter="Text Formatter"
    machineName="."
    />

to a new value say source = "My Application", I don't get the log in none of the two destinations.  

dnfan

 

 

 

Dec 14, 2009 at 8:11 AM

Hi,

Still the same results. I still get the logs on both destination even i change the source of the event log trace listener. Can you send a sample repro project if possible?

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