MSEL 5 has been working like a charm for us, but off late I have been trying to configure additional "categorySources" but the result is always the same. The log entry is always made using the "defaultCategory" and the following error is logged in the log file "Message: There is no explicit mapping for the categories 'AppLogGen'. The log entry was: "

The web.config "loggingConfiguration" entry

  <loggingConfiguration name="" tracingEnabled="true" defaultCategory="AppLog">
<listeners>
  <add name="Flat File Trace Listener" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
    listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
    fileName="c:\LoggingTrace\trace.log" formatter="Text Formatter"
    rollFileExistsBehavior="Increment" rollInterval="Midnight" rollSizeKB="10000"
    timeStampPattern="dd-MM-yyyy" traceOutputOptions="None" filter="All" />
  <add name="Flat File Trace Listener Login" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
    listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
    fileName="c:\LoggingTrace\traceLogin.log" formatter="Text Formatter Login"
    rollFileExistsBehavior="Increment" rollInterval="Midnight" rollSizeKB="10000"
    timeStampPattern="dd-MM-yyyy" traceOutputOptions="None" filter="All" />
</listeners>
<formatters>
  <add type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
    template="Format 1:: Timestamp: {timestamp(local)}{newline}&#xA;Message: {message}{newline}&#xA;Category: {category}{newline}&#xA;"
    name="Text Formatter" />
  <add type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
    template="Format 2:: Timestamp: {timestamp(local)}{newline}&#xA;Message: {message}{newline}&#xA;Category: {category}{newline}&#xA;"
    name="Text Formatter Login" />
</formatters>
<categorySources>
  <add switchValue="All" name="InfinityWeb">
    <listeners>
      <add name="Flat File Trace Listener" />
    </listeners>
  </add>
  <add switchValue="All" name="AppLog">
    <listeners>
      <add name="Flat File Trace Listener Login" />
    </listeners>
  </add>
  <add switchValue="All" name="AppLogGen">
    <listeners>
      <add name="Flat File Trace Listener Login" />
    </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="Flat File Trace Listener" />
    </listeners>
  </errors>
</specialSources>

The code, writing to the log file

            //logWriter.Write(message, category, priority, eventId, (TraceEventType)severity, DefaultTitle, null);
        LogEntry logEntry = new LogEntry();
        logEntry.Categories.Add("AppLogGen");
        logEntry.Message = "Override " + message;

        logWriter.Write(logEntry);

The ouput in the log file

Timestamp: 9/6/2012 1:15:23 PM

Message: There is no explicit mapping for the categories 'AppLogGen'. The log entry was:

Timestamp: 9/6/2012 7:45:23 AM

Message: Override Login successful for UserId:Admin

Category: AppLogGen

Severity: Information Category: AppLog . . . Extended Properties:

Irrespective of what I do, the logging always uses the category source specified in "defaultCategory". Already spent two days on this one. Help!

1

There are 1 best solutions below

1
On
<allEvents switchValue="All" name="All Events" />
    <listeners>
      <add name="Flat File Trace Listener" />
    </listeners>

These lines of code have the issue. "Flat File Trace" Listener is the default listener for all events. so whatever event would happen would be listen by default listner. You should check by commenting this listener.