0

Can ASP.NET's System.web.Management be used for logging events like user logins, password changes and access to certain resources? Should system.Web.Management be used for logging of errors and health monitoring instead?

I want to log events without re-inventing the whole thing. I know ELMAH is used for errors; can it be used for logging events too?

Pops
  • 30,199
  • 37
  • 136
  • 151
Greens
  • 3,061
  • 11
  • 43
  • 61

1 Answers1

1

From the article ELMAH - Error Logging Modules And Handlers on the now defunct DoNetSlackers:

Error signaling is exposed via the ErrorSignal class, which provides a single overloaded method called Raise. Simply put, exceptions raised via the ErrorSignal class are not thrown, therefore they don't bubble up, but instead are only sent out to ELMAH, as well as to whomever subscribes to the Raise event of the ErrorSignal class.

The code snippet below shows how to obtain an instance of the ErrorSignal class, which is unique per application and can be retrieved simply with the static FromCurrentContext method, and then use it to signal an exception.

ErrorSignal.FromCurrentContext().Raise(new NotSupportedException());

The difference between signaling and throwing an exception is that in the first case no one will ever know about the error except ELMAH.

Further Reading:

KyleMit
  • 30,350
  • 66
  • 462
  • 664
ggonsalv
  • 1,264
  • 8
  • 18