Friday, 25 June 2021
Yet another post to remind me how to do this in future as I couldn't find any clear documentation.
It turns out that it's actually quite simple to configure Umbraco to log to App Insights.
This assumes that you have already created the App Insights instance in Azure and noted the Instrumentation Key.
First, you need to configure your project to have the necessary dependencies. This is the same process for any ASP.NET MVC (for .NET Framework) based web application.
Follow the instructions here. Apply these changes to your web application, where Umbraco is installed.
This will start logging exceptions and requests to App Insights, but not Umbraco logs.
Umbraco uses Serilog for logging, so we just need to install the Serilog "sink" to send logs to App Insights.
Serilog.Sinks.ApplicationInsights NuGet package (latest version is fine).
With the sink package installed, add the following to the
<appSettings /> section of the
config/serilog.user.config file in your Umbraco project.
1<add key="serilog:using:ApplicationInsights" value="Serilog.Sinks.ApplicationInsights"/> 2<add key="serilog:write-to:ApplicationInsights.telemetryConverter" value="Serilog.Sinks.ApplicationInsights.Sinks.ApplicationInsights.TelemetryConverters.TraceTelemetryConverter, Serilog.Sinks.ApplicationInsights"/> 3<add key="serilog:minimum-level:override:Microsoft" value="Warning" />
It can take some time (up to ~15 minutes) for logs to come through to App Insights.
In the Logs section of your App Insights instance, you can query
requests to see the HTTP requests,
exceptions for any exceptions that have been thrown and
traces for any Umbraco logs.