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.
Build the application, run it in the browser, and navigate to http://www.yoursite.com/elmah.axd. You are prompted to log in before you see the content. After a successful authentication, you see a web page to remotely view the entire log of recorded exceptions.
ELMAH provides a simple, yet powerful mechanism for logging errors in an ASP.NET web application. Like Microsoft's health monitoring system, ELMAH can log errors to a database and can send the error details to a developer via email.
ELMAH (Error Logging Modules and Handlers) is an application-wide error logging facility that is completely pluggable. It can be dynamically added to a running ASP.NET web application, or even all ASP.NET web applications on a machine, without any need for re-compilation or re-deployment.
You can view the logging information in folder App_Data/Sitefinity/Logs. For more information about the Enterprise Library, see The Logging Application Block on the MSDN. ELMAH logs the following: ErrorLog.
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 Elmah.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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With