You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The simplest way to configure Serilog to send data to a Application Insights dashboard via instrumentation key is to use
9
-
current active *telemetry configuration* which is already initialised in most application types like ASP.NET Core, Azure
10
-
Functions etc.:
14
+
The recommended way to configure the sink is to reuse the `TelemetryConfiguration` (or `TelemetryClient`) already configured by your application (for example via dependency injection in ASP.NET Core, Azure Functions, Worker Services).
Legacy: some older application types used `TelemetryConfiguration.Active`. This is not recommended on modern .NET and may be deprecated depending on the Application Insights SDK version.
35
+
26
36
> You can also pass an *instrumentation key* and this sink will create a new `TelemetryConfiguration` based on it,
27
37
> however it's actively discouraged compared to using already initialised telemetry configuration, as your telemetry
@@ -57,10 +67,10 @@ startup errors can be caught and properly logged. The problem is that now we're
57
67
to setup the logger early, but we need the `TelemetryConfiguration` which still haven't been added to our DI container.
58
68
59
69
Luckily [from version 4.0.x of the `Serilog.Extensions.Hosting` we have the possibility to configure a bootstrap logger](https://nblumhardt.com/2020/10/bootstrap-logger/)
60
-
to capture early errors, and then change it using DI dependant services once they are configured.
70
+
to capture early errors, and then change it using DI-dependent services once they are configured.
Application Insight supports component version and is pushed out if you set `version` log event property. If it's
380
+
Application Insight supports component version and is pushed out if you set `Version` log event property. If it's
358
381
present, AI's operation version will include the value from this property.
359
382
383
+
## Using with SerilogTracing
384
+
385
+
[SerilogTracing](https://github.com/serilog-tracing/serilog-tracing) provides tracing primitives that integrate with Serilog's structured logging. When used with this sink, tracing context is automatically included in Application Insights telemetry.
386
+
387
+
The following `LogEvent` properties are mapped to Application Insights telemetry:
If present, `Baggage` is forwarded to Application Insights custom dimensions (`telemetry.Properties`).
399
+
400
+
Precedence for `Context.Operation.Id`: `OperationId` property > `TraceId` property (when both `OperationId` and `TraceId` properties are absent).
401
+
402
+
### Enriching from `Activity` (explicit opt-in)
403
+
404
+
This sink is designed to work well with Serilog's asynchronous/batched processing. To keep telemetry deterministic, adding `OperationName` and `Baggage` from the ambient `Activity` is an explicit opt-in: copy the values onto the `LogEvent` before it reaches the sink.
405
+
406
+
The sink includes an enricher that adds this by default. Enable it using the provided `Enrich` extension method:
This is a new major release (5.0). Notable changes:
418
+
419
+
-**OperationName and Baggage are opt-in:** they are only forwarded when present as `LogEvent` properties (use the built-in enricher above or your own enricher).
420
+
-**Less redundancy in custom dimensions by default:** operation-related values are set on `ITelemetry.Context` and are not duplicated into `telemetry.Properties` unless enabled.
421
+
422
+
### `TelemetryConverterBase` constructor flags
423
+
424
+
Converters derived from `TelemetryConverterBase` can be configured to also include selected operation-related values in `telemetry.Properties` (custom dimensions):
If you previously relied on these values being present in `telemetry.Properties`, enable the relevant flags when constructing your converter, or post-process telemetry in a custom converter.
435
+
360
436
## Using with Azure Functions
361
437
362
438
Azure functions has out of the box integration with Application Insights, which automatically logs functions execution
363
439
start, end, and any exception. Please refer to
364
-
the [original documenation](https://docs.microsoft.com/en-us/azure/azure-functions/functions-monitoring) on how to
440
+
the [original documentation](https://docs.microsoft.com/en-us/azure/azure-functions/functions-monitoring) on how to
365
441
enable it.
366
442
367
443
This sink can enrich AI messages, preserving *operation_Id* and other context information which is *already provided by
0 commit comments