Created
May 31, 2023 14:10
-
-
Save cocowalla/7b404cacf3bc4b742dd9ddb301c66c4c to your computer and use it in GitHub Desktop.
A rough example of how to use Serilog.Sinks.OpenTelemetry to send logs to Azure Application Insights
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
builder | |
.UseSerilog((ctx, _, logConfig) => | |
{ | |
logConfig.ReadFrom.Configuration(ctx.Configuration, "Log"); | |
}, writeToProviders: true) | |
.ConfigureServices((ctx, services) => | |
{ | |
services.AddOpenTelemetry() | |
.ConfigureResource(res => { | |
... | |
}) | |
.WithTracing(tracing => | |
{ | |
... | |
}) | |
.WithMetrics(metrics => | |
{ | |
... | |
}); | |
}) | |
.ConfigureLogging((ctx, logBuilder) => | |
{ | |
logBuilder.ClearProviders(); | |
logBuilder.AddOpenTelemetry(options => | |
{ | |
options.SetResourceBuilder(ConfigureResource(ctx)); | |
options.AddAzureMonitorLogExporter(x => | |
{ | |
x.ConnectionString = "My App Insights Connection String"; | |
}); | |
options.IncludeFormattedMessage = true; | |
options.IncludeScopes = true; | |
options.ParseStateValues = true; | |
}); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Project> | |
... | |
<ItemGroup> | |
<PackageReference Include="Serilog" Version="2.12.0" /> | |
<PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.5.0-alpha.2" /> | |
<PackageReference Include="OpenTelemetry.Exporter.Console" Version="1.5.0-alpha.2" /> | |
<PackageReference Include="Azure.Monitor.OpenTelemetry.Exporter" Version="1.0.0-beta.10" /> | |
</ItemGroup> | |
</Project> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment