Build status NuGet Samples

Logging to elmah.io from SignalR

Logging from SignalR is supported through our Elmah.Io.Extensions.Logging package. For details not included in this article, check out Logging from Microsoft.Extensions.Logging.

Start by installing the Elmah.Io.Extensions.Logging package:

Install-Package Elmah.Io.Extensions.Logging
dotnet add package Elmah.Io.Extensions.Logging
<PackageReference Include="Elmah.Io.Extensions.Logging" Version="3.*" />
paket add Elmah.Io.Extensions.Logging

In the Program.cs file, add a new using statement:

using Elmah.Io.Extensions.Logging;

Then call the ConfigureLogging-method and configure elmah.io like shown here:

public static IHostBuilder CreateHostBuilder(string[] args) =>
    Host.CreateDefaultBuilder(args)
        .ConfigureWebHostDefaults(webBuilder =>
        {
            webBuilder.UseStartup<Startup>();
            webBuilder.ConfigureLogging((ctx, logging) =>
            {
                logging.AddElmahIo(options =>
                {
                    options.ApiKey = "API_KEY";
                    options.LogId = new Guid("LOG_ID");
                });
                logging.AddFilter<ElmahIoLoggerProvider>(null, LogLevel.Warning);
            });
        });

Replace API_KEY with your API key (Where is my API key?) and LOG_ID (Where is my log ID?) with the log Id of the log you want to log to.

The code only logs Warning, Error, and Fatal messages. To change that you can change the LogLevel filter specified in the last line of the ConfigureLogging method. You may also need to change log levels for SignalR itself:

logging.AddFilter("Microsoft.AspNetCore.SignalR", LogLevel.Debug);
logging.AddFilter("Microsoft.AspNetCore.Http.Connections", LogLevel.Debug);

Be aware that changing log levels to Debug or lower will cause a lot of messages to be stored in elmah.io.


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