无法在 Azure 中找到 WebJob 的日志文件

Unable to find the log file of WebJob in Azure

我在 Azure 中创建了一个 WebJob。我使用了 Nlog 并将日志文件指向 WebJob 的 exe 文件的 "base directory"。 Web 作业已创建,并且 运行ning 成功,没有任何错误。此外,Nlog 正在我的本地系统中创建日志文件。但是天蓝色,我找不到日志文件。我进入 "app_data\jobs\triggered" 文件夹并找到了我创建的作业。但是没有创建日志文件。我能够在 azure 中编写和查看控制台日志。

编辑

Program.cs

using NLog; 
using System;

namespace FacilitationPortal.WebJob {
    class Program
    {
        static Logger logger = LogManager.GetCurrentClassLogger();
    static void Main(string[] args)
    {
        string nlogServicePath = AppDomain.CurrentDomain.BaseDirectory + "NLog-WebSchedulerService.config";

        NLog.LogManager.Configuration = new NLog.Config.XmlLoggingConfiguration(nlogServicePath, true);
        logger.Debug("Initializing the Web Scheduler Service");
        Console.WriteLine("Initializing the Web Scheduler Service");
        StartServices();
    }

    private static void StartServices()
    {
        logger.Debug("INSIDE - START SERVICES");
    }
    } 
}

NLog-WebSchedulerService.config 文件

<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" autoReload="true">
  <targets >
    <target xsi:type="File" name="logfile"
            fileName="${basedir}/logs/WebScheduler.log"
            layout="${longdate} ${level:uppercase=true:padding=5} ${gdc:item=hostname} ${gdc:item=useremail} (${logger} - ${mdc:item=actionname})  ${message} ${exception:format=tostring}"
            archiveEvery="Day"
            archiveFileName ="${basedir}/logs/WebScheduler.${date:format=yyyy-MM-dd HH.mm}.{#}.zip"
            archiveNumbering ="Sequence"
            maxArchiveFiles="30"
            fileAttributes="Compressed"
            enableArchiveFileCompression = "true">
    </target>
  </targets>
  <rules>
    <logger name="*" minlevel="Debug" writeTo="logfile">
    </logger>
  </rules>
</nlog>

Console.WriteLine() 正在 Azure 控制台中打印日志。但是 logger.Debug() 没有在 exe 存在的地方创建日志文件。如果我 运行 在本地系统中使用相同的应用程序,则正在创建日志文件。

谢谢

首先,使用你的 NLog-WebSchedulerService.config 并持续部署 运行 WebJob 到 Azure,我可以在 D:\local\Temp\jobs\continuous\WebJob1hxylleo.lzh\logs 文件夹下找到日志,你可以检查你的日志文件是否在 D:\local\Temp\jobs\triggered文件夹。

此外,正如我之前的评论中提到的,您可以在 Azure 上指定一个现有的物理目录来存储日志,例如 fileName="D:\home\data\logs\WebScheduler.log",而不是将日志存储在 D:\local\Temp 文件夹下。