Build status NuGet Samples

Logging to elmah.io from Azure WebJobs

Logging errors from Azure WebJobs requires only a few lines of code. We've created a client specifically for Azure WebJobs.

Support for Azure WebJobs has been stopped on version 3.1.23 of the Elmah.Io.Functions package. The newer versions only work with Azure Functions.

Install the Elmah.Io.Functions package:

Install-Package Elmah.Io.Functions -Version 3.1.23
dotnet add package Elmah.Io.Functions --version 3.1.23
<PackageReference Include="Elmah.Io.Functions" Version="3.1.23" />
paket add Elmah.Io.Functions --version 3.1.23

Log all uncaught exceptions using the ElmahIoExceptionFilter attribute:

[ElmahIoExceptionFilter("API_KEY", "LOG_ID")]
public class Functions
{
    public static void ProcessQueueMessage([QueueTrigger("queue")] string msg, TextWriter log)
    {
        throw new Exception("Some exception");
    }
}

Replace API_KEY with your API key (Where is my API key?) and LOG_ID (Where is my log ID?) with your log ID.

If your WebJob method is declared as async, remember to change the return type to Task. Without it, ElmahIoExceptionFilter is never invoked.

The filter also supports config variables:

[ElmahIoExceptionFilter("%apiKey%", "%logId%")]

The variables above, would require you to add your API key and log ID to your App.config:

<configuration>
  <appSettings>
    <add key="apiKey" value="API_KEY"/>
    <add key="logId" value="LOG_ID"/>
  </appSettings>
</configuration>


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