Rolling file listener lock behavior

Topics: Logging Application Block
Oct 23, 2012 at 12:39 PM

EntLib 5.0

I switched from having logging settings specified in web.config to using the fluent API. As far as I can tell, the settings are equivalent, but the behavior is different:

  • With web.config settings, I could delete the flat file at any time (it would not be locked).
  • With the programmatic configuration, the file is always locked.

I would prefer that it *not* be locked...

Two different approaches are below. Am I missing something obvious?

 

  <loggingConfiguration name="" tracingEnabled="false" defaultCategory="AppDebug">
    <logFilters>
      <add name="LogEnabled Filter" type="Microsoft.Practices.EnterpriseLibrary.Logging.Filters.LogEnabledFilter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" enabled="false" />
    </logFilters>
    <listeners>
      <add name="SVRFILE" 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="App_Data\\Logs\\MvcAppDebugLog.txt" formatter="Text Formatter" rollFileExistsBehavior="Increment" rollInterval="Day" maxArchivedFiles="50" traceOutputOptions="None" />
    </listeners>
    <formatters>
      <add type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" template="{message}{newline}" name="Text Formatter" />
    </formatters>
    <categorySources>
      <add switchValue="Error" name="EllucianAppDebug">
        <listeners>
          <add name="SVRFILE" />
        </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="SVRFILE" />
        </listeners>
      </errors>
    </specialSources>
  </loggingConfiguration>

 

And code approach:

            ConfigurationSourceBuilder builder = new ConfigurationSourceBuilder();
            builder.ConfigureLogging().LogToCategoryNamed("AppDebug").
                SendTo.               
                RollingFile("SVRFILE")
                .ToFile(filename)
                .FormatWith(new FormatterBuilder().TextFormatterNamed("textFormatter").UsingTemplate("{message}{newline}"))
                .WhenRollFileExists(RollFileExistsBehavior.Increment)
                .RollEvery(RollInterval.Day)
                .CleanUpArchivedFilesWhenMoreThan(50)
                .WithTraceOptions(TraceOptions.None)
                .Filter(sourceLevel);

            var configSource = new DictionaryConfigurationSource();
            builder.UpdateConfigurationWithReplace(configSource);
            EnterpriseLibraryContainer.Current = EnterpriseLibraryContainer.CreateDefaultContainer(configSource);

Oct 24, 2012 at 6:50 PM

Files should be locked irrespective how they are configured.  To be sure, I did a test (using WebDev and IIS) and was unable to delete the file (because it was "In Use") using a configuration based approach.

--
Randy Levy
Enterprise Library support engineer
entlib.support@live.com