Alik Levin's

Clarity, Technology, and Solving Problems | PracticeThis.com

ASP.NET Health Monitoring Means Logging And Auditing

ASP.NET Health Monitoring Means Logging And Auditing

  • Comments 5

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

  • 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)

  • 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

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

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

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

Page 1 of 1 (5 items)