I am wondering how do I create my customized provider for storing the error logs, eg. a provider to windows event viewer.
If it is not possible so far, I am also wondering is there any exposed events I can override, so that I can inject my code, get the exception, do whatever I want.
I know there are some event I can override in Global.asax. like for filtering:
void ErrorLog_Filtering(object sender, ExceptionFilterEventArgs e)
{
}
void ErrorMail_Filtering(object sender, ExceptionFilterEventArgs )
{
}
is there more? where can I find the list of these events?
About creating an Elmah Event Log provider it's probably not a good idea if you intend to store the error information in the event log and also use the ELMAH UI. A related question has an excellent answer from Matthew Daugherty on this topic:
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.
In order to create a custom logging provider you can subclass ErrorLog and override the GetError (gets a single error by id; used by the Elmah UI), GetErrors (lists all errors on a page; used by the Elmah UI) and Log (logs a new error) methods to provide your own storage mechanism. See this article for an examle on how to implement a custom ErrorLog.
You then register your new ErrorLog provider in the config:
<elmah>
<errorLog type="MyNamespace.MyErrorLog, MyAssemblyName"/>
</elmah>
Regarding the events, they are emitted by the Elmah modules. In the ErrorLogModule there are two events - Logged and Filtering. In the ErrorMailModule there are four events - Filtering, Mailing, Mailed and DisposingMail.
来源:https://stackoverflow.com/questions/5363088/elmah-customized-provider-and-exposed-event