Elmah error logging, can I just log a message?

user603007 picture user603007 · Aug 8, 2013 · Viewed 13k times · Source

I just installed Elmah (https://code.google.com/p/elmah/) for my ASP.NET application. Is it possible to log a message without creating an Exception first?

catch(Exception e)
{
    Exception ex = new Exception("ID = 1", e);
    ErrorSignal.FromCurrentContext().Raise(ex);
}

So is it possible to do:

ErrorSignal.FromCurrentContext().log("Hello I am testing Elmah");

Answer

Chris Schiffhauer picture Chris Schiffhauer · Aug 8, 2013

Yes, you can use ErrorSignal without throwing an exception.

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

For the custom message, you can create a custom exception.

var customEx = new Exception("Hello I am testing Elmah", new NotSupportedException()); 
ErrorSignal.FromCurrentContext().Raise(customEx);