{"id":15422583,"url":"https://github.com/heaths/keyvaultclientlogging","last_synced_at":"2025-06-28T05:32:37.442Z","repository":{"id":145642743,"uuid":"286875155","full_name":"heaths/KeyVaultClientLogging","owner":"heaths","description":"Sample showing how to log with KeyVaultClient","archived":false,"fork":false,"pushed_at":"2020-08-20T22:27:05.000Z","size":10,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-26T06:58:09.293Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C#","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/heaths.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-08-12T00:13:06.000Z","updated_at":"2020-08-20T22:27:08.000Z","dependencies_parsed_at":null,"dependency_job_id":"82639c9a-0e09-4b30-b428-c1ac07ffa9d4","html_url":"https://github.com/heaths/KeyVaultClientLogging","commit_stats":{"total_commits":3,"total_committers":1,"mean_commits":3.0,"dds":0.0,"last_synced_commit":"4ff4cd08600a03b494f022ec16cf4a15b63e23d2"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/heaths/KeyVaultClientLogging","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/heaths%2FKeyVaultClientLogging","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/heaths%2FKeyVaultClientLogging/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/heaths%2FKeyVaultClientLogging/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/heaths%2FKeyVaultClientLogging/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/heaths","download_url":"https://codeload.github.com/heaths/KeyVaultClientLogging/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/heaths%2FKeyVaultClientLogging/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262381730,"owners_count":23302255,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-01T17:38:58.698Z","updated_at":"2025-06-28T05:32:37.390Z","avatar_url":"https://github.com/heaths.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Logging example for KeyVaultClient\n\nWhile we recommend customers upgrade to any of the following three packages with improved logging, extensibility, and performance, we understand not everyone can move right away and may need support with the older `KeyVaultClient` class from [Microsoft.Azure.KeyVault](https://www.nuget.org/packages/Microsoft.Azure.KeyVault/). This sample helps demonstrate how you can add logging to your application.\n\n## Recommended packages\n\nWe recommend you use any of the following packages as needed. See \u003chttps://aka.ms/azsdk/intro\u003e for reasons.\n\n* [Azure.Security.KeyVault.Certificates](https://www.nuget.org/packages/Azure.Security.KeyVault.Certificates/)\n* [Azure.Security.KeyVault.Keys](https://www.nuget.org/packages/Azure.Security.KeyVault.Keys/)\n* [Azure.Security.KeyVault.Secrets](https://www.nuget.org/packages/Azure.Security.KeyVault.Secrets/)\n\n## Logging packages\n\nYou need to add one or more of the following logging packages, or write your own class that implements `IServiceClientTracingInterceptor` from [Microsoft.Rest.ClientRuntime](https://www.nuget.org/packages/Microsoft.Rest.ClientRuntime/):\n\n* [Microsoft.Rest.ClientRuntime.Etw](https://www.nuget.org/packages/Microsoft.Rest.ClientRuntime.Etw/) ([README](https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/mgmtcommon/ClientRuntime.Etw/README.md))\n* [Microsoft.Rest.ClientRuntime.Log4Net](https://www.nuget.org/packages/Microsoft.Rest.ClientRuntime.Log4Net/) ([README](https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/mgmtcommon/ClientRuntime.Log4Net/README.md))\n\nThe sample code in this project uses `Microsoft.Rest.ClientRuntime.Etw`, which has almost no overhead if no ETW listeners are configured, which you can do with tools like *logman.exe* (installed with Windows), [perfview.exe](https://github.com/microsoft/perfview/), and more.\n\n### Code changes\n\nTo enable logging, you have to add trace listeners to your code and enable logging:\n\n```csharp\nServiceClientTracing.AddTracingInterceptor(new EtwTracingInterceptor());\nServiceClientTracing.IsEnabled = true;\n```\n\nIn contrast, using the new Azure.\\* packages like those recommended above enables secure logging by default. That is, no personally-identifiable information (PII) is logged. You can *skip* making code changes and listen for `Azure` events, like `Azure-Core` for pipeline requests and responses. Read [Tracing Azure SDK for .NET](https://heaths.dev/azure/2020/02/04/trace-azure-sdk-for-net.html) for more information.\n\n## Tracing events\n\n.NET Core uses an `EventSource` to log data, which [uses ETW on Windows and LTTng on Linux](https://docs.microsoft.com/dotnet/core/diagnostics/logging-tracing#logging-events). If you are running on the .NET Framework on Windows, you can use a configuration file like the included [app.config](app.config), though this has no effect on .NET Core.\n\nNote that logging data from `HttpClient` will likely log personally identifiable information (PII) including secret information like bearer tokens. In our newer Azure.\\* packages, we not only obfuscate such information (only some headers are logged, while all others are sanitized) but we do not log content by default, since content will likely contain PII.\n\n### PerfView\n\nThe easiest way to collect traces for any process on your system is to download [PerfView](https://github.com/microsoft/perfview/):\n\n1. Run *perfview.exe*.\n1. Click **Collect** -\u003e **Collect**. If prompted to elevate, do so since tracing requires elevated privileges.\n1. Expand **Advanced Options**.\n1. In **Additional Providers:**, enter exactly: `*Microsoft.Rest`\n1. *Optional*: If you want to log all messages from `HttpClient` used internally, enter exactly: `*Microsoft-System-Net-Http,*Microsoft.Rest`\n1. Click **Start Collection**.\n1. After running your application such as this sample application, click **Stop Collection**.\n1. After processing completes (may take a while), double click **Events**.\n1. Scroll down events starting with \"Microsoft.Rest\".\n\n### dotnet-trace\n\nAnother useful and cross-platform tool is dotnet-trace:\n\n1. Run: `dotnet tool install -g dotnet-trace`\n1. Run this sample: `dotnet run`\n1. The sample application will print the process ID and pause for you to hit **Enter**.\n1. Run the following, replacing `\u003cProcess ID\u003e` with the process ID printed from above: `dotnet trace collect --providers Microsoft.Rest -p \u003cProcess ID\u003e`\n1. *Optional*: If you want to log all messages from `HttpClient` used internally, enter instead: `dotnet trace collect --providers Microsoft-System-Net-Http,Microsoft.Rest -p \u003cProcess ID\u003e`\n1. Tracing will automatically stop and write the events to *trace.nettrace* in the current directory by default.\n\nYou can open *trace.nettrace* with PerfView. As above, find the events starting with \"Microsoft.Rest\".\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fheaths%2Fkeyvaultclientlogging","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fheaths%2Fkeyvaultclientlogging","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fheaths%2Fkeyvaultclientlogging/lists"}