如何通过存储帐户 Uri 或 appSettings.json 中的命名连接字符串将 Serilog 配置为 WriteTo AzureBlobStorage?

发布于 2025-01-13 08:54:43 字数 1223 浏览 2 评论 0原文

当进行以下部分时,Serilog 配置正确。 暴露了connectionString,被添加到appSettings.json中:

"Serilog": {
  "WriteTo": [
    {
      "Name": "AzureBlobStorage",
      "Args": {
        "connectionString": "DefaultEndpointsProtocol=https;AccountName=mystorage;AccountKey=...;EndpointSuffix=core.windows.net",
        //"connectionStringName": "MyStorageConnectionName",
        //"storageAccountUri": "https://mystorage.blob.core.windows.net",
        "storageContainerName": "myapplogs",
        "storageFileName": "MyApp {yyyy}-{MM}-{dd}.log",
        "writeInBatches": "true", // mandatory
        "period": "0.00:00:30", // mandatory
        "batchPostingLimit": "50" // optional
      }
    }, ...
  ],
}

虽然上述方法有效,但到目前为止我还无法将connectionString属性的使用替换为connectionStringName< /strong> 或最好是 storageAccountUri (只需利用托管身份。)

我已按照建议添加了 Serilog.Settings.Configuration 3.3.0此处;我正在配置 Serilog,如下所示:

static void createLogger(ConfigureHostBuilder host) {
  host.UseSerilog((ctx, lc) => {
    lc.ReadFrom.Configuration(ctx.Configuration);
  });
}

Serilog configures properly when the following section. which exposes connectionString, is added to appSettings.json:

"Serilog": {
  "WriteTo": [
    {
      "Name": "AzureBlobStorage",
      "Args": {
        "connectionString": "DefaultEndpointsProtocol=https;AccountName=mystorage;AccountKey=...;EndpointSuffix=core.windows.net",
        //"connectionStringName": "MyStorageConnectionName",
        //"storageAccountUri": "https://mystorage.blob.core.windows.net",
        "storageContainerName": "myapplogs",
        "storageFileName": "MyApp {yyyy}-{MM}-{dd}.log",
        "writeInBatches": "true", // mandatory
        "period": "0.00:00:30", // mandatory
        "batchPostingLimit": "50" // optional
      }
    }, ...
  ],
}

While the above works, I have thus far been unable to replace use of the connectionString property with either connectionStringName or preferably storageAccountUri (simply leveraging Managed Identities.)

I have added the Serilog.Settings.Configuration 3.3.0 package as suggested here; and I am configuring Serilog as follows:

static void createLogger(ConfigureHostBuilder host) {
  host.UseSerilog((ctx, lc) => {
    lc.ReadFrom.Configuration(ctx.Configuration);
  });
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

冧九 2025-01-20 08:54:43

我正在使用非常相似的配置......
我能够让它与 ConnectionStringName 一起使用,但不能与 storageAccountUri 一起使用(这比能够使用托管身份更好)

I am using a very similar configuration...
I was able to get it to work with ConnectionStringName but NOT with the storageAccountUri (which would be preferable to be able to use Managed Identity)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文