清理 HttpClient 日志工具 0.0.3

dotnet add package SanitizedHttpClientLogger --version 0.0.3                
NuGet\Install-Package SanitizedHttpClientLogger -Version 0.0.3                
此命令旨在在 Visual Studio 的包管理器控制台内使用,因为它使用了 NuGet 模块的 Install-Package 的版本。
<PackageReference Include="SanitizedHttpClientLogger" Version="0.0.3" />                
对于支持 PackageReference 的项目,将此 XML 节点复制到项目文件中以引用此包。
paket add SanitizedHttpClientLogger --version 0.0.3                
#r "nuget: SanitizedHttpClientLogger, 0.0.3"                
#r 指令可以在 F# Interactive 和 Polyglot Notebooks 中使用。将此复制到交互式工具或脚本的源代码中,以引用此包。
// Install SanitizedHttpClientLogger as a Cake Addin
#addin nuget:?package=SanitizedHttpClientLogger&version=0.0.3

// Install SanitizedHttpClientLogger as a Cake Tool
#tool nuget:?package=SanitizedHttpClientLogger&version=0.0.3                

它是如何工作的

无法配置基于 Microsoft.Extensions.HttpHttpClient 日志记录器的日志模式。它必须被替换。

此包使用以下日志记录器替换默认的日志记录器

  1. HttpClient 请求的日志语句数量从 4 减少到 2
  2. 确保敏感信息,如 api 密钥或请求 Uri 中的令牌,可以通过可配置的正则表达式模式进行清理

日志输出更改

之前

info: Start processing HTTP request GET https://my.api.com/v1/status?apikey=my-secret-key
info: Sending HTTP request GET https://my.api.com/v1/status?apikey=my-secret-key
info: Received HTTP response headers after 188.6041ms - 200
info: End processing HTTP request after 188.8026ms - 200

之后

info: Sending HTTP request GET https://my.api.com/v1/status?apikey=xxx
info: Received HTTP response GET https://my.api.com/v1/status?apikey=xxx - 200 in 186.4883ms

安装

$ dotnet add package SanitizedHttpClientLogger

用法

通过选项
services
    .AddHttpClient<Worker>((_, o) =>
    {
        o.BaseAddress = new Uri("https://my.api.com/v1");
    })
    .ConfigureSanitizedLogging(o =>
        // This regex pattern will match any part of a string that starts with "apikey=" (in a case-insensitive manner)
        // followed by any number of characters that are not an ampersand.    
        o.RequestUriReplacements.Add("(?i)apikey=[^&]*", "apikey=xxx")
    );
通过配置
{
  "SanitizedHttpLoggerOptions": {
    "RequestUriReplacements": {
      "(?i)apikey=[^&]*": "apikey=xxx"
    }
  }
}
services
    .AddHttpClient<Worker>((_, o) =>
    {
        o.BaseAddress = new Uri("https://my.api.com/v1");
    })
    .ConfigureSanitizedLogging(configuration);
产品 兼容和额外的计算目标框架版本。
.NET net8.0 兼容。 net8.0-android 已计算。 net8.0-browser 已计算。 net8.0-ios 已计算。 net8.0-maccatalyst 已计算。 net8.0-macos 已计算。 net8.0-tvos 已计算。 net8.0-windows 已计算。
兼容的目标框架
包含的目标框架(在包中)
了解更多关于 目标框架.NET Standard 的信息。

NuGet 包 (1)

显示依赖 SanitizedHttpClientLogger 的前 1 个 NuGet 包

下载
Freecurrency-API

此非官方(基于 RestEase)客户端允许与 freecurrencyapi(https://freecurrencyapi.com)进行交互

GitHub 仓库

此包没有被任何流行的 GitHub 仓库使用。

版本 下载 最后更新
0.0.3 174 3/20/2024

# 0.0.2 (2024 年 3 月 20 日)
- #2 添加 SanitizedHttpClientLogger [增强]

完整发布说明可以在这里找到: https://github.com/StefH/SanitizedHttpLogger/blob/main/ReleaseNotes.md