I am using ELMAH in my ASP.NET MVC projects and I really like its simplicity. But I needed the ability to log certain events in my code in a log.Info("message") manner. Since ELMAH does not provide that ability I started looking at NLog.
A few questions came to mind:
Anny feedback is greatly appreciated. So far I haven't found any good posts on this matter?
Create a Console Application project in Visual Studio. Install NLog and its dependencies. Create and configure the NLog logger. Integrate the logger into the C# Console Application.
NLog is “a free logging platform for . NET, Silverlight and Windows Phone with rich log routing and management capabilities. It makes it easy to produce and manage high-quality logs for your application regardless of its size or complexity.”
NLog is a . Net Library that enables you to add high-quality logs for your application. NLog can also be downloaded using Nugget in Visual Studio. Targets are used to display, store, or pass log messages to another destination.
Answering question number 2, I just read this article where it explains how to log un-handled exceptions with NLog. Basically is adding in the Global.asax.cs file something like:
protected void Application_Error()
{
Exception lastException = Server.GetLastError();
NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
logger.Fatal(lastException);
}
You can in fact trigger an alert from ELMAH. Like so:
ErrorSignal.FromCurrentContext().Raise(new System.ApplicationException("An error occured in SendEmail()", ex));
Don't forget to add a reference to elmah.dll and add using Elmah;
to the file.
See here for a bit more examples.
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