Logging from ServiceStack

Logging errors to elmah.io from ServiceStack is almost as easy as installing in MVC and Web API. The folks over at ServiceStack provide you with a NuGet package named ServiceStack.Logging.Elmah. Like Web API you need to tell ServiceStack to use ELMAH as logging framework for errors, besides adding the standard ELMAH configuration in web.config. Start by installing both ServiceStack.Logging.Elmah and elmah.io into your ServiceStack web project:

Install-Package ServiceStack.Logging.Elmah
Install-Package Elmah.Io

During the installation, you will be asked for your API key (Where is my API key?) and log ID (Where is my log ID?).

Once installed, add the following line to your AppHost:

LogManager.LogFactory = new ElmahLogFactory(new NLogFactory());

The above example assumes that you are already using NLog as the existing framework for logging. Wrapping different logger factories in each other and actually makes it possible to log errors through ELMAH and other types of messages like warnings and info messages through another logging framework. If you don’t need anything other than ELMAH logging, use the NullLogFactory instead of NLogFactory.

That’s it! By installing both the ServiceStack.Logging.Elmah and elmah.io packages, you should have sufficient configuration in your web.config to start logging like a pro.


This article was brought to you by the elmah.io team. elmah.io is the best error management system for .NET web applications. We monitor your website, alert you when errors start happening and help you fix errors fast.

Monitor your website



Comments