Skip to content

Commit

Permalink
Add logging with Azure.Monitor.OpenTelemetry.AspNetCore section
Browse files Browse the repository at this point in the history
Updates Azure SDK .NET logging article according to Azure/azure-sdk-for-net#42374
  • Loading branch information
lmolkova authored Mar 6, 2024
1 parent d00db0d commit ad95553
Showing 1 changed file with 25 additions and 0 deletions.
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 libraris.
You can control logging using any of the [Logging in .NET Core and ASP.NET Core configuration options](/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

```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

0 comments on commit ad95553

Please sign in to comment.