How do I use "ActivityTracing"?

Topics: Logging Application Block
Feb 18, 2011 at 6:21 PM

One of the minimum category options in the logging settings is for "ActivityTracing." I understand the options for All, Critical, Error, etc., as these are all severity settings. However, there is no severity setting for "ActivityTracing," so how is this option consumed?

I am thinking it should be something like:

Logger.Write(string.Format("Getting Login info for user: {0}", login.LoginName), "Trace", "ActivityTracing");

However, there is no method overload for this.

Feb 21, 2011 at 5:24 AM

Hi BillyM,

The "ActivityTracing" is included in the System.Diagnostics.SourceLevels enumeration which is used as a filter in switchValue of category sources. 

            <add switchValue="ActivityTracing" name="General">
                    <add name="Event Log Listener" />

The switchValue is mapped  to the Severity (System.Diagnostics.TraceEventType) of the LogEntry. In this case the switchValue is set to 'ActivityTracing' meaning that the source will only process LogEntries of severities of 'Stop', 'Start', 'Suspend', 'Transfer'. Instance of listeners also uses SourceLevels as a filter for log processing.

            <add name="Event Log Listener" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FormattedEventLogTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
                listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FormattedEventLogTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
                source="Enterprise Library Logging" formatter="Text Formatter"
                log="" machineName="." traceOutputOptions="None" filter="ActivityTracing" />

In your case, the Logger is expecting a severity with a 'specific activity tracing'  (Start, Stop, Suspend, Transfer, Resume). Your code will looks like this:

Logger.Write(string.Format("Getting Login info for user: {0}", login.LoginName), "Trace", System.Diagnostics.TraceEventType.Start /*(or Stop, Suspend, Transfer, Resume depending on your needs)*/);

"ActivityTracing" is most commonly use in the scenario wherein you have a tracing log and you want to disable error logging on it.