【问题标题】:Unable to find the log file of WebJob in Azure在 Azure 中找不到 WebJob 的日志文件
【发布时间】:2017-09-14 10:09:15
【问题描述】:

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

编辑

程序.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 所在的位置创建日志文件。如果我在本地系统中运行相同的应用程序,则会创建日志文件。

谢谢

【问题讨论】:

  • 能否贴出相关代码?
  • 我把${basedir}替换成已有的物理目录,比如fileName="D:\home\data\logs\WebScheduler.log",发现日志是在Azure里创建的,你可以试试。

标签: c# nlog azure-webjobs


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-11-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-24
    • 1970-01-01
    相关资源
    最近更新 更多