Ent Lib 5 Logging block - creating multiple files with Guid at start of the file for the same trace

Topics: Logging Application Block
May 13, 2013 at 10:42 AM
I know it was asked here for a number of times but I'm not sure what am I doing wrong here.
I have a multi threaded application, one app Domain.
I am getting many logging files with guid before them for the same log file listener.
In the code I Log in the following way:
/// <summary>
        /// writes a log entry
        /// </summary>
        /// <param name="message">the message to log</param>
        /// <param name="priority">log priority</param>
        /// <param name="categroy">log category</param>
        public static void Log(string message, LogPriority priority, LogCategory categroy)
        {
            var log = new LogEntry
                          {
                              Message = message, 
                              Priority = ((int) priority), 
                              TimeStamp = DateTime.Now
                          };
            log.Categories.Add(categroy.ToString());
            try
            {
                Logger.Write(log);
            }
My configuration file:
<loggingConfiguration name="Logging Application Block" tracingEnabled="true" defaultCategory="Unknown" logWarningsWhenNoCategoriesMatch="true">
<listeners>
  <add name="flow log" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging" fileName="C:\projects\RABIT\HDMT\logs\Rabit_flow_log.log" footer="----------------------------------------" formatter="RabitTextFormater" header="----------------------------------------" rollFileExistsBehavior="Increment" rollInterval="None" rollSizeKB="10000" timeStampPattern="yyyy-MM-dd" traceOutputOptions="None" filter="All"/>
  <add name="Rolling Detailed log" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging" fileName="C:\projects\RABIT\HDMT\logs\RABIT_OPERATION_LOG.log" footer="----------------------------------------" formatter="RabitTextFormater" header="----------------------------------------" rollFileExistsBehavior="Increment" rollInterval="Day" rollSizeKB="10000" timeStampPattern="yyyy-MM-dd" traceOutputOptions="None" filter="All"/>
  <add name="Rolling Error Log" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging" fileName="C:\projects\RABIT\HDMT\logs\RABIT_ERROR_LOG.log" footer="----------------------------------------" formatter="RabitTextFormater" header="----------------------------------------" rollFileExistsBehavior="Increment" rollInterval="None" rollSizeKB="10000" timeStampPattern="yyyy-MM-dd" traceOutputOptions="None" filter="All"/>
  <add name="Rolling Unit Log" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging" fileName="C:\projects\RABIT\HDMT\logs\RABIT_UNIT_LOG.log" footer="----------------------------------------" formatter="RabitTextFormater" header="----------------------------------------" rollFileExistsBehavior="Increment" rollInterval="Day" rollSizeKB="10000" timeStampPattern="yyyy-MM-dd" traceOutputOptions="None" filter="All"/>
</listeners>
<formatters>
  <add type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging" template="{timestamp(MM/dd/yyyy hh:mm:ss.fff tt)}: {message}&#xD;&#xA;Category: {category}, Priority: {priority}, Severity: {severity}&#xD;&#xA;Thread Name: {threadName}, Process Name: {processName}, Win32 Thread Id: {win32ThreadId}, Machine Name: {machine}"

                                                                                                               name="RabitTextFormater"/>
</formatters>
<logFilters>
  <add type="Microsoft.Practices.EnterpriseLibrary.Logging.Filters.CategoryFilter, Microsoft.Practices.EnterpriseLibrary.Logging" categoryFilterMode="AllowAllExceptDenied" name="Category Filter"/>
  <add type="Microsoft.Practices.EnterpriseLibrary.Logging.Filters.LogEnabledFilter, Microsoft.Practices.EnterpriseLibrary.Logging" enabled="true" name="LogEnabled Filter"/>
  <add type="Microsoft.Practices.EnterpriseLibrary.Logging.Filters.PriorityFilter, Microsoft.Practices.EnterpriseLibrary.Logging" minimumPriority="-1" maximumPriority="2147483647" name="Priority Filter"/>
</logFilters>
<categorySources>
  <add switchValue="All" name="Communication"/>
  <add switchValue="All" name="Entities"/>
  <add switchValue="All" name="Error">
    <listeners>
      <add name="Rolling Error Log"/>
    </listeners>
  </add>
  <add switchValue="All" name="Flow">
    <listeners>
      <add name="flow log"/>
    </listeners>
  </add>
  <add switchValue="All" name="Robot"/>
  <add switchValue="All" name="Steps"/>
  <add switchValue="All" name="Unit">
    <listeners>
      <add name="Rolling Unit Log"/>
    </listeners>
  </add>
  <add switchValue="All" name="Unknown"/>
</categorySources>
<specialSources>
  <allEvents switchValue="All" name="All Events">
    <listeners>
      <add name="Rolling Detailed log"/>
    </listeners>
  </allEvents>
  <notProcessed switchValue="All" name="Unprocessed Category"/>
  <errors switchValue="All" name="Logging Errors &amp; Warnings">
    <listeners>
      <add name="Rolling Error Log"/>
    </listeners>
  </errors>
</specialSources>
</loggingConfiguration>
May 13, 2013 at 4:24 PM
I don't see anything wrong with what you've posted. Internally the static Logger shares the same LogWriter instance and all calls to write are synchronized to allow for thread safety so there shouldn't be a problem.

Can you provide more information about how you are initializing Enterprise Library (if at all)? A small sample that demonstrates the behavior would help in tracking down the issue.

~~
Randy Levy
entlib.support@live.com
Enterprise Library support engineer
Support How-to