Elmah error logging, can I just log a message?

半腔热情 提交于 2019-12-02 23:46:46

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.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!