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.
@@ -375,7 +384,7 @@ present, AI's operation version will include the value from this property.
375
384
376
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.
377
386
378
-
The following LogEvent properties are mapped to Application Insights telemetry:
387
+
The following `LogEvent` properties are mapped to Application Insights telemetry:
If present, `Baggage` is forwarded to Application Insights custom dimensions (`telemetry.Properties`).
399
+
389
400
Precedence for `Context.Operation.Id`: `operationId` property > `TraceId` property (when both `operationId` and `TraceId` properties are absent).
390
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
+
Two built-in enrichers are included:
407
+
408
+
-`ActivityOperationNameEnricher` — copies `Activity.OperationName` into the `OperationName` log event property.
409
+
-`ActivityBaggageEnricher` — copies baggage items from the current `Activity` into the `Baggage` log event property as a `StructureValue`.
410
+
411
+
Enable them using the provided `Enrich` extension methods:
This is a new major release (5.0). Notable changes:
424
+
425
+
-**OperationName and Baggage are opt-in:** they are only forwarded when present as `LogEvent` properties (use the built-in enrichers above or your own enricher).
426
+
-**Less redundancy in custom dimensions by default:** operation-related values are set on `ITelemetry.Context` and are not duplicated into `telemetry.Properties` unless enabled.
427
+
428
+
### `TelemetryConverterBase` constructor flags
429
+
430
+
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.
441
+
391
442
## Using with Azure Functions
392
443
393
444
Azure functions has out of the box integration with Application Insights, which automatically logs functions execution
394
445
start, end, and any exception. Please refer to
395
-
the [original documenation](https://docs.microsoft.com/en-us/azure/azure-functions/functions-monitoring) on how to
446
+
the [original documentation](https://docs.microsoft.com/en-us/azure/azure-functions/functions-monitoring) on how to
396
447
enable it.
397
448
398
449
This sink can enrich AI messages, preserving *operation_Id* and other context information which is *already provided by
0 commit comments