Elmah error logging, can I just log a message? Elmah error logging, can I just log a message? asp.net asp.net

Elmah error logging, can I just log a message?


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


Try this

Elmah.ErrorSignal.FromCurrentContext().Raise(new Exception("Your message"));


I know this is an old question, but if you don't want to create an exception you can also use

var error = new Error{   Source = eventType.ToString(),   Type = $"Trace-{eventType}",   Message = message,   Time = DateTime.UtcNow};ErrorLog.GetDefault(HttpContext.Current).Log(error);

as shown in this answer.