views:

181

answers:

1

We are using ELMAH to log the web application exception which works great!. Also we want to know how to customize ELMAH to log the windows service exception.

I am not interested in using another application for logging only windows service exception.

Any help would be appreciated.

A: 

Hi,

I did this previously. I found out the code to use by digging though the source code starting from the ErrorSignal.FromCurrentContext().Raise(ex); method.

This currently only logs to the Database (as thats all i needed) but with a little bit more investigation you could write a wrapper method that logs to whatever you have set-up in the config file.

try
{

Elmah.SqlErrorLog ErrorLog = new Elmah.SqlErrorLog(ConfigurationManager.ConnectionStrings["Default"].ConnectionString);

ErrorLog.ApplicationName = "AppName";

ErrorLog.Log(new Error(new Exception("example"));

}
catch (Exception ex)
{
    //catch sql error
}

In my service I made the ErrorLog variable a public singleton object that was easily accessed from the service project.

Hope this helps,

K

Keith K