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

.NET 4.8中如何配置NLog将日志写入Azure文件共享

配置NLog将日志写入Azure文件共享(.NET 4.8)

你的原配置无法生效,是因为NLog的File目标仅支持本地文件系统或已映射的网络驱动器路径,无法直接识别Azure文件共享的HTTP/HTTPS格式地址。以下是两种可行的解决方案:

方法一:映射Azure文件共享为本地驱动器

  1. 将Azure文件共享映射到本地网络驱动器(比如Z盘),执行命令:
    net use Z: \\myazurestorageaccount.file.core.windows.net\fs1 /u:AZURE\myazurestorageaccount <你的存储账户密钥>
    
    (注:可将该命令加入系统启动脚本,避免重启后需重新映射)
  2. 修改NLog配置中的fileName为映射后的驱动器路径:
    <targets>
      <target name="fileTarget"
              xsi:type="File"
              fileName="Z:\example.log"
            />
    </targets>
    

方法二:使用NLog Azure存储扩展目标

  1. 安装针对.NET Framework 4.8的NLog.AzureStorage NuGet包
  2. 在App.config中配置专门的Azure文件共享目标,无需手动映射驱动器:
    <targets>
      <target name="azureFileTarget"
              xsi:type="AzureFile"
              connectionString="DefaultEndpointsProtocol=https;AccountName=myazurestorageaccount;AccountKey=你的存储账户密钥;"
              shareName="fs1"
              fileName="example.log"
            />
    </targets>
    <!-- 添加日志路由规则 -->
    <rules>
      <logger name="*" minlevel="Info" writeTo="azureFileTarget" />
    </rules>
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.18 21:05:20