Logging to elmah.io 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 the 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
dotnet add package ServiceStack.Logging.Elmah
dotnet add package Elmah.Io
<PackageReference Include="ServiceStack.Logging.Elmah" Version="5.*" />
<PackageReference Include="Elmah.Io" Version="5.*" />
paket add ServiceStack.Logging.Elmah
paket add 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 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 errors.


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.

See how we can help you monitor your website for crashes Monitor your website