Setting application name

If logging to the same log from multiple applications, it might be a good idea to set an application name on all log messages. This will let you search for errors generated by a specific application through the elmah.io UI. Also, ELMAH automatically sets the application name to the Guid of the application inside IIS, why it often looks better to either clear this or set something meaningful.

The application name can be easily set from the web.config file as part of the elmah.io configuration:

<errorLog type="Elmah.Io.ErrorLog, Elmah.Io" apiKey="API_KEY" logId="LOG_ID" applicationName="MyApp" />

This will decorate all errors logged to elmah.io with the application name MyApp.

A common use of Web.config Transformations is to have a transformation per environment, customer, application, etc. If this is the case, you can replace the application name as part of the config transformation. Check out Use multiple logs for different environments for more information about how to update the errorLog element.

Our Web.config transformations - The definitive syntax guide contains general information about how transformations work and you can use the Web.config Transformation Tester to validate transformation files.

If you, for some reason, cannot set the application name in the web.config file, it can be specified from C# by including the following code in the Application_Start method in the global.asax.cs file:

Elmah.ErrorLog.GetDefault(null); // Forces creation of logger client
var logger = Elmah.Io.ErrorLog.Client;
logger.OnMessage += (sender, args) =>
{
    args.Message.Application = "MyApp";
};


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