ASP.NET Health Monitoring Means Logging And Auditing

I constantly keep seeing ASP.NET developers using log4net for logging and auditing their Web apps. While I have nothing against log4net - it is great stuff I presume though never used it - it is pretty funny to me to get why people do not use built-in ASP.NET 2.0 Health Monitoring. I started to ask - turns out people are just not aware of it...

Our logging story with ASP.NET 1.1 was pretty bad although with small effort one could do very cool things with TraceListener.

I think it was mistake calling it Health Monitoring since folks miss it - no one looks for Health Monitoring but logging or may be auditing.

So here is detailed how-to for ASP.NET 2.0 Auditing and Logging, ...ehm ...Health Monitoring:

How To: Use Health Monitoring in ASP.NET 2.0

How To: Instrument ASP.NET 2.0 Applications for Security

 

For those who still on ASP.NET 1.1 similar pluggable design can be achieved by implementing Custom TraceListener. Then registering it with web.config. In order to send error message to it one uses standard System.Diagnostics.Trace.WriteLine(message);

Here is custom TraceListener:

namespace DeepDive2004
{

public class CustomListener : TextWriterTraceListener
{
public CustomListener() : base()
{
}

public CustomListener(string initData)
{

}

public override void Write(string message)
{
//ACTUAL CODE TO SEND MESSAGES TO SOME STORE, SAY WEB SERVICE
base.Write (message);
}
public override void WriteLine(string message)
{
//ACTUAL CODE TO SEND MESSAGES TO SOME STORE, , SAY WEB SERVICE
base.WriteLine (message);
}

}

}

and here is web.config configuration:

<system.diagnostics>
<trace autoflush="true" indentsize="0">
<listeners>
<add name="MyCustomListener"
type="DeepDive2004.CustomListener, DeepDive2004"
initializeData="http://MyWebService"/>
</listeners>
</trace>
</system.diagnostics>

Those who is interested in using log4net I suggest reading Mitch's excellent post log4net: .NET Logging Tool

Ed. - After posting this one I've jsut noticed your personal approach to my question here Logging and ASP.NET Health Monitoring.

Mitch, you rock, man!

Enjoy

Published 02 May 07 07:35 by alikl

Comments

# Anatoly Lubarsky said on May 3, 2007 3:37 PM:

Well, everything is nice, however asp.net web app. is not a winform app, therefore need to monitor in addition:

1) app. shutdown events (recycles): http://weblogs.asp.net/scottgu/archive/2005/12/14/433194.aspx

2) javascript exceptions (essential when you have a big site)

# alikl said on May 3, 2007 3:53 PM:

Agree, it is Web stuff. But with webforms you usually use web services, where you can use same health monitoring. For winforms it is more debug log and you can use builtin System.Diagnostics.Trace to report failures or success. The events would be picked by configured tracelistenr - either standard (event log or file) or custom - see example in the post

# alik levin's said on May 18, 2007 6:57 AM:

My favorite design patterns is Provider design pattern (abstract factory – GoF definition) . I like it

# alik levin's said on July 16, 2007 1:42 PM:

"Unspecified error", "Catastrophic failure", "Object reference not set to an instance of an object" and

# alik levin's said on January 20, 2008 12:02 PM:

patterns &amp; practices team maintains Design for Operations [DFO] project on codeplex . The goal of

New Comments to this post are disabled

Search

Go

This Blog

. My Personal Blog .

.Net Performance How To's

.Net Security How To's

Design Patterns

Impactful

Lifecycle Phases

Popular

Tools

Syndication

Page view tracker