Setting up logging

The following describes how to set up logging when using the Storm API.

Make sure the following is present in the configuration file under configuration:

  <configSections>
    <section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging" requirePermission="true" />
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
  </configSections>

log4net is used by the LogEntries logprovider and can be skipped if not used.

Here’s a sample of the logging configuration:

 <loggingConfiguration name="" tracingEnabled="true" defaultCategory="Debug" logWarningsWhenNoCategoriesMatch="true">
    <listeners>
      <add name="UnprocessedListener" type="Enferno.Public.Logging.RollingXmlTraceListener, Enferno.Public" listenerDataType="Enferno.Public.Logging.Configuration.RollingXmlTraceListenerData, Enferno.Public" fileName="C:\Temp\Logs\YourApplication\Unprocessed.svclog" rollFileExistsBehavior="Increment" rollInterval="Day" maxArchivedFiles="6" traceOutputOptions="LogicalOperationStack, DateTime, Timestamp, ProcessId, ThreadId" />
      <add name="AlertListener" type="Enferno.Public.Logging.RollingXmlTraceListener, Enferno.Public" listenerDataType="Enferno.Public.Logging.Configuration.RollingXmlTraceListenerData, Enferno.Public" fileName="C:\Temp\Logs\YourApplication\Alert.svclog" rollFileExistsBehavior="Increment" rollInterval="Month" maxArchivedFiles="2" traceOutputOptions="LogicalOperationStack, DateTime, Timestamp, ProcessId, ThreadId" />
      <add name="LogEntriesAlert" loggerName="Alert" type="Enferno.Public.Logging.Log4NetTraceListener, Enferno.Public.Logging" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.CustomTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging" formatter="LogEntriesFormatter" />
    </listeners>
    <formatters>
      <add name="LogEntriesFormatter" type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging" template="{newline}Message: {message}{newline}Machine: {machine}{newline}Categories: {category}{newline}ActivityId: {activity}{newline}ErrorMessage: {errorMessages}{newline}{dictionary({key}: {value}{newline})}" />
    </formatters>
    <logFilters>
      <add type="Microsoft.Practices.EnterpriseLibrary.Logging.Filters.LogEnabledFilter, Microsoft.Practices.EnterpriseLibrary.Logging" enabled="true" name="Logging Enabled Filter" />
    </logFilters>
    <categorySources>
      <add switchValue="Warning" name="Alert">
        <listeners>
          <add name="AlertListener" />
          <add name="LogEntriesAlert" />
        </listeners>
      </add>
      </add>      
    </categorySources>
    <specialSources>
      <allEvents switchValue="Off" name="All Events">
        <listeners>
          <add name="UnprocessedListener" />
        </listeners>
      </allEvents>
      <notProcessed switchValue="All" name="Unprocessed Category">
        <listeners>
          <add name="UnprocessedListener" />
        </listeners>
      </notProcessed>
      <errors switchValue="All" name="Logging Errors &amp; Warnings">
        <listeners>
          <add name="UnprocessedListener" />
        </listeners>
      </errors>
    </specialSources>
  </loggingConfiguration>

If using LogEntries see How to set up LogEntries for Logging for more details.