Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add logging with Azure.Monitor.OpenTelemetry.AspNetCore section #39854

Merged
merged 6 commits into from
Apr 1, 2024
Merged
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions docs/azure/sdk/logging.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,31 @@ In these scenarios, complete the following steps:

For more information, see [Logging in .NET Core and ASP.NET Core](/aspnet/core/fundamentals/logging/).

## Logging using Azure.Monitor.OpenTelemetry.AspNetCore

[Azure Monitor OpenTelemetry Distro](https://www.nuget.org/packages/Azure.Monitor.OpenTelemetry.AspNetCore), starting with version `1.2.0`, supports capturing logs coming from Azure client libraries.
You can control logging using any of the configuration options discussed in [Logging in .NET Core and ASP.NET Core](/aspnet/core/fundamentals/logging/).

Using the Azure Service Bus library as an example, complete the following steps:

1. Install the [Azure.Monitor.OpenTelemetry.AspNetCore](https://www.nuget.org/packages/Azure.Monitor.OpenTelemetry.AspNetCore) NuGet package:

```dotnetcli
dotnet add package Azure.Monitor.OpenTelemetry.AspNetCore
```

1. Create or register the Azure SDK library's client - the distro supports both cases
lmolkova marked this conversation as resolved.
Show resolved Hide resolved

```csharp
await using var client = new ServiceBusClient("<connection_string>");
```

1. In *appsettings.json*, change the Service Bus library's default log level. For example, toggle it to `Debug` by setting the `Logging:LogLevel:Azure.Messaging.ServiceBus` key as follows:

:::code language="json" source="snippets/logging/appsettings.Development.json" highlight="9":::

Since the `Logging:LogLevel:Azure.Messaging.ServiceBus` key is set to `Debug`, Service Bus client events up to `EventLevel.Verbose` will be logged.

## Log HTTP request and response bodies

When troubleshooting unexpected behavior with a client library, it's helpful to inspect the following items:
Expand Down
Loading