MessageHandler MH Sign Up

How to configure logging


The MessageHandler runtime and engines perform their logging operations using the Microsoft.Extensions.Logging.ILogger abstraction.

This abstraction is automatically provided when hosting in the dotnet generic hosting abstration or any of the framework provided derivatives, such as the ASP.NET Core Web Host.

When hosted in the ASP.NET Core Web Host the following providers are automatically provided.

  • Console
  • Debug
  • EventSource

Each of these targets can be monitored within visual studio using the respective output or events windows.

These default logging targets are great for local development, but not for azure hosted deployments.

Logging to Azure Application Insights

To send the log statements towards Azure Application Insights, you need to either install the Microsoft.ApplicationInsights.AspNetCore or Microsoft.ApplicationInsights.WorkerService nuget package depending on the host, WebHost and GenericHost respectively.

When hosting in the WebHost, call AddApplicationInsightsTelemetry;


When hosting in the Generic Host, call AddApplicationInsightsTelemetryWorkerService;


The default logging level set in the WebHost is Warning, while none is set for the Generic Host. In both cases you may want to set the loglevel to information to see the output of the MessageHandler runtimes, which are usually logged at the Information log level;

builder.Logging.AddFilter<ApplicationInsightsLoggerProvider>(level => level >= LogLevel.Information);

MessageHandler is running quite a few processes, among others the outbox, the atomic and the stream processing runtimes, run on background threads in Hosted Services. Luckily the Microsoft.ApplicationInsights.AspNetCore also handles these when hosted in a web host, so there is never a need to install both packages.

For more information on how to configure Application Insights in more detail, refer to the official Microsoft documentation

Sign up to our newsletter to get notified about new content and releases

You can unsubscribe at any time by clicking the link in the footer of your emails. I use Mailchimp as my marketing platform. By clicking subscribe, you acknowledge that your information will be transferred to Mailchimp for processing. Learn more about Mailchimp's privacy practices here.