You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

.NET Standard 2.0中NLog写入AzureBlobStorage的Info级日志失效问题

问题:NLog.Extensions.AzureBlobStorage无法写入Info级日志(复杂字符串场景异常)

环境配置

  • .NET Standard 2.0 项目
  • 引用 NuGet 包:
<PackageReference Include="NLog.Extensions.AzureBlobStorage" Version="4.2.0" />

异常现象

  • 日志写入Azure Blob Storage整体正常,但Info级日志无法写入
  • 尝试将所有日志写入单个文件时,文件为空;按日志级别分文件存储时,仅Info级日志文件为空

日志目标配置代码

string blobName = $"{this.AzureStorageBlobNamePrefix}_${{shortdate}}_${{level}}.log";
// 创建Azure Blob Storage目标
BlobStorageTarget blobStorageTarget = new()
{
    Name = blobStorageTargetName,
    ConnectionString = this.AzureStorageConnectionString,
    Container = this.AzureStorageContainerName,
    BlobName = blobName,
    Layout = layout,
};

// 将Azure Blob Storage目标添加到LoggingConfiguration
config.AddTarget(blobStorageTargetName, blobStorageTarget);

// 创建规则,将目标与所需日志事件关联
var rule = new LoggingRule("*", LogLevel.Trace, blobStorageTarget);
config.LoggingRules.Add(rule);

关键发现:复杂字符串调用差异

  • 直接调用函数生成字符串:logger.Info(GetMyString(p)) → 生成空日志
  • 使用延迟委托调用:logger.Info(() => GetMyString(p)) → 正常生成预期日志

内容的提问来源于stack exchange,提问作者Sebastian

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.17 12:05:08