Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ELMAH error logging for Windows Service

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.

like image 663
Gabriel Susai Avatar asked Mar 08 '10 14:03

Gabriel Susai


People also ask

How do I view the ELMAH error log?

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.

What is ELMAH error?

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.

What does ELMAH stand for?

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.

Where are ELMAH logs stored?

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.


1 Answers

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.

like image 161
Keith K Avatar answered Oct 11 '22 14:10

Keith K