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="https://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