user1396423
user1396423

Reputation: 263

Unable to find the log file of WebJob in Azure

I have created a WebJob in Azure. I have used Nlog and point the log file to the "base directory" of the WebJob's exe file. Web job is created and it is running successfully without any errors. Also, Nlog is creating the log file in my local system. But in azure, I am not able to find the log file. I went into the "app_data\jobs\triggered" folder and found the job which I have created. But the log file is not getting created. I am able to write and see the console log in azure.

EDIT

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 file

<?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() is printing the log in azure console. But logger.Debug() is not creating log file in the place where the exe is present. If I run the same application in my local system, log file is creating.

Thanks

Upvotes: 2

Views: 2241

Answers (1)

Fei Han
Fei Han

Reputation: 27825

Firstly, using your NLog-WebSchedulerService.config and deploying a continuously running WebJob to Azure, I can find the logs under D:\local\Temp\jobs\continuous\WebJob1\1hxylleo.lzh\logs folder, you can check if your logs file under D:\local\Temp\jobs\triggered folder.

enter image description here

Besides, as I mentioned in my early comment, you can specify an existing physical directory on Azure to store the logs, such as fileName="D:\home\data\logs\WebScheduler.log", instead of storing the logs under D:\local\Temp folder.

Upvotes: 4

Related Questions