it:ad:enterpriselibrary:logging

IT:AD:NET:Libraries:EnterpriseLibrary:Logging

Summary

EntLib Logging Flow

* Read this!!!

  • App logs using static class Logger or LogWriter class, or by directly creating an instance of the LogEntry class and populating it with the information to log.
  • The log entry can define a set of categories that map to the categories defined in the configuration. This mapping controls the processes that the block applies to the log entry (the filters and sources that it uses).
  • The log writer passes the log entry through the log filters that we define in the configuration. These filters can block the log entry based on its priority, category name, or when logging is not enabled.
  • If the log filters do not block the log entry, the log writer retrieves the appropriate trace sources. The trace sources we can use consist of a set of category sources that we create and configure, and three special sources that we can use to ensure that the block will record all log entries (for example, if there is an error within the logging system or if the log entry does not match any configured category).
  • We can configure one or more trace listeners for each of the trace sources. In other words, we can configure a specific set of trace listeners for each category that the message might contain, and for each of the three special sources that might handle the message. The log writer will pass the log entry to the matching trace listeners we specify.
  • The trace listener then uses a log formatter to transform the information in the log entry into an appropriate format, such as formatted text or binary, and writes the result to the output specific to the type of trace listener. Depending on the trace listener type, the output can go to a file, a database, WMI, Message

Example:

<configuration>
  <configSections>
    <section name="enterpriseLibrary.ConfigurationSource" 
             type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ConfigurationSourceSection, 
             Microsoft.Practices.EnterpriseLibrary.Common, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" 
             requirePermission="true" />
    <section name="loggingConfiguration" 
             type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, 
                   Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" 
                   requirePermission="true" />
  </configSections>


  <enterpriseLibrary.ConfigurationSource selectedSource="System Configuration Source">
    <sources>
    <add name="System Configuration Source" 
         type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.SystemConfigurationSource, 
               Microsoft.Practices.EnterpriseLibrary.Common, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
    </sources>
  </enterpriseLibrary.ConfigurationSource>
  <loggingConfiguration name="" tracingEnabled="true" defaultCategory="General">
    <listeners>
    <add name="Rolling Flat File Trace Listener" 
         type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, 
               Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
         listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, 
                           Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
         fileName="rolling2.log" 
         formatter="Text Formatter" 
         rollInterval="Day"
         rollSizeKB="100" 
         traceOutputOptions="DateTime, Timestamp" />
    </listeners>

    <formatters>
      <add type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, 
                 Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
           template="Timestamp: {timestamp}{newline}&#xA;Message: {message}{newline}
                     &#xA;Category: {category}{newline}
                     &#xA;Priority: {priority}{newline}
                     &#xA;EventId: {eventid}{newline}
                     &#xA;Severity: {severity}{newline}
                     &#xA;Title:{title}{newline}
                     &#xA;Machine: {localMachine}{newline}
                     &#xA;App Domain: {localAppDomain}{newline}
                     &#xA;ProcessId: {localProcessId}{newline}
                     &#xA;Process Name: {localProcessName}{newline}
                     &#xA;Thread Name: {threadName}{newline}
                     &#xA;Win32 ThreadId:{win32ThreadId}{newline}
                     &#xA;Extended Properties: {dictionary({key} - {value}{newline})}"
           name="Text Formatter" />
    </formatters>
    <categorySources>
      <add switchValue="All" name="General">
        <listeners>
          <add name="Rolling Flat File Trace Listener" />
        </listeners>
      </add>
    </categorySources>

    <specialSources>
      <allEvents switchValue="All" name="All Events">
        <listeners>
          <add name="Rolling Flat File Trace Listener" />
        </listeners>
      </allEvents>
      <notProcessed switchValue="All" name="Unprocessed Category">
        <listeners>
          <add name="Rolling Flat File Trace Listener" />
        </listeners>
      </notProcessed>
      <errors switchValue="All" name="Logging Errors &amp; Warnings">
        <listeners>
          <add name="Rolling Flat File Trace Listener" />
        </listeners>
      </errors>
    </specialSources>
  </loggingConfiguration>
</configuration>
  • /home/skysigal/public_html/data/pages/it/ad/enterpriselibrary/logging.txt
  • Last modified: 2023/11/04 03:24
  • by 127.0.0.1