Log errors in EventLog using ELMAH

女生的网名这么多〃 提交于 2019-12-22 07:53:10

问题


I am using ELMAH to log errors in my asp.net MVC(C#) application.

I am able to log errors in xml or database. How to log errors to the eventlog using ELMAH?


回答1:


ELMAH does not include an event log option.

ELMAH error log classes are not write-only; they also read the log data so that it can be displayed in the ELMAH web interface. Additionally, ELMAH logs more than just exception information. It also logs server variables, the form collection, and the information necessary to reproduce the yellow screen of death. Even if you were to log all of this information to the event log it would be difficult to read as plain text, and very difficult to read back in such a way that the ELMAH web interface could use it. If you are not going to use the ELMAH web interface then clearly that is not an issue.

If you want to log basic exception data to the event log you can create your own error log by subclassing ErrorLog. ELMAH supports multiple error logs, so you could continue to log detailed data to XML or a database (to service the ELMAH web interface) and then log a subset of that data to the event log.




回答2:


Out of the box, you can't. You'd have to write a custom handler.




回答3:


You can do something like this.

Elmah.ErrorSignal.FromCurrentContext().Raise(new Exception("My Exception");


来源:https://stackoverflow.com/questions/1978555/log-errors-in-eventlog-using-elmah

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