问题
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