2017-09-13 54 views
1

我在Azure中創建了WebJob。我已經使用Nlog並將日誌文件指向WebJob的exe文件的「基礎目錄」。 Web作業已創建並且正在成功運行,沒有任何錯誤。另外,Nlog正在我的本地系統中創建日誌文件。但在azure中,我無法找到日誌文件。我進入了「app_data \ jobs \ triggered」文件夾並找到了我創建的作業。但是日誌文件沒有被創建。我能夠編寫並看到天藍色的控制檯日誌。無法在Azure中找到WebJob的日誌文件

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文件

<?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()被打印在日誌中天青控制檯。但是logger.Debug()不會在exe文件存在的地方創建日誌文件。如果我在本地系統中運行相同的應用程序,則會創建日誌文件。

感謝

+0

請問您可以發佈相關代碼嗎? – Thomas

+1

我用現有的物理目錄(如fileName =「D:\ home \ data \ logs \ WebScheduler.log」)替換''{{basedir}'',我發現日誌是在Azure中創建的,你可以嘗試一下。 –

回答

1

首先,使用NLog-WebSchedulerService.config和部署連續運行WebJob天青,我能找到D:\local\Temp\jobs\continuous\WebJob1\1hxylleo.lzh\logs文件夾下的日誌,你可以檢查你的日誌D:\local\Temp\jobs\triggered文件夾下的文件。

enter image description here

此外,正如我在我早期的評論中提到,你可以在Azure上指定現有物理目錄來存儲,而不是D:\local\Temp文件夾下存儲日誌日誌,如fileName="D:\home\data\logs\WebScheduler.log"