Rolling Log File Provider for ASP.NET 2.0 Health Monitoring

The RollingLogWebEventProvider is a plugin for the ASP.NET 2.0 Health Monitoring API. The RollingLogWebEventProvider provides a mechanism for the standard ASP.NET Health Monitoring API similiar to log4Net's RollingFileAppender, or the Enterprise Library's RollingFlatFileTraceListener. To use the RollingLogWebEventProvider requires no additional source code, only some additional ASP.NET health monitoring configuration settings. An example of these settings are as follows:-

<?xml version="1.0"?>
        <compilation debug="true" />

      <healthMonitoring enabled="true">
          <add  name="All Logged Errors Default"
                    eventName="All Errors"
                    profile="Default" minInstances="1"
          <add  name="RollingLogFileProvider" 
                    bufferMode="Critical Notification" 
                    layout="%Type,  %EventCode, %EventTimeUtc, %Message, %ToString"/>

Parameters specific to the configuration for the RollingLogWebEventProvider are as follows:-

path A path to a directory in which log files are created. This can either be a real physical path on the server, or an application relative virtual path.
datePattern X Specifies the file name format used. The default is yyyyMMdd, meaning a file created on the 1/4/2006 would be named 20060401.log

Roll style can be set to one of the following values

Size - Roll files based only on the size of the file
Date - Roll files based only on the date
Composite - Roll files based on both the size and date of the file

maximumFileSize X Specifies the maximum size a log file should grow to in kilobytes, when the roll style is set to Size or Composite. The default size for log files is 100KB. When a log file exceeds it's size limit it's it is renamed with an extension number the file.  Newer files are numbered greater than older files.
maxNumRolledLogs X Specifies the number of log files that should be kept. A number less than 1 may be used to specify an infinite number of backups. The default is 50.
layout X

Used to specifies the layout of the log file and to specifiy what properties of an event should be logged. The following keywords can be used to format log entries:-

%eventcode - WebBaseEvent.EventCode
%type - WebBaseEvent.Message
%eventdetailcode - WebBaseEvent.EventDetailCode
%eventid - WebBaseEvent.EventID
%eventoccurrence - WebBaseEvent.EventOccurrence
%eventsequence - WebBaseEvent.EventSequence
%eventsource - WebBaseEvent.EventSource
%eventtimeutc - WebBaseEvent.EventTimeUtc
%eventtime - WebBaseEvent.EventTime
%message - WebBaseEvent.Message
%accountname - WebManagementEvent.WebProcessInformation.AccountName
%processid - WebManagementEvent.WebProcessInformation.ProcessID
%processname - WebManagementEvent.WebProcessInformation.ProcessName
%exceptiontype - WebBaseErrorEvent.ErrorException type
%innerexceptiontype - WebBaseErrorEvent.ErrorException.InnerException type
%helplink - WebBaseErrorEvent.ErrorException.HelpLink
%exceptionmessage - WebBaseErrorEvent.ErrorException.Message
%innerexceptionmessage - WebBaseErrorEvent.ErrorException.InnerException.Message
%source - WebBaseErrorEvent.ErrorException.Source
%stacktrace - WebBaseErrorEvent.ErrorException.StackTrace
%tostring - WebBaseEvent.ToString()

The default layout pattern is:-

%EventCode, %Type, %EventDetailCode, %EventID, %EventOccurrence, %EventSequence, %EventSource, %EventTime, %EventTimeUtc, %Message, %ToString

Keywords are case independent.

The RollingLogWebEventProvider is freely available from the Downloads page.

Simply add a reference to the MBLM.Web.Management.dll assembly in your project and then add then add elements to your web.config as demonstrated above and in the sample web site.

Published: Wednesday, August 01, 2007 1:32 PM by Michael Lang
Kick it


Leave a comment

Your Name (required):
Your Url (optional):
Title (required):
Your Comment (required):

MBLM Logic Check - Protection from spiders and scripts

Guarding against malicious attacks on the web is an unfortunate necessity. To prove your request is authentic, provide answer to the question below.

Enter the answer in numerical format e.g. Q: two + two A: 4
Compute: zero add forty-nine


Microsoft.NET services, software and development resources