日志文件未通过NLog保存在Azure Blob存储上

时间:2019-05-21 08:10:19

标签: c# nlog

您好,我第一次使用Azure Blob存储和NLog。我想将我的所有日​​志和文件上传到Blob存储以及FTP文件夹。我能够将这些日志文件存储在Blob上,但是面临将这些文件保存在Blob容器上的问题。 我正在使用以下代码

    <?xml version="1.0"?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" throwException="true" autoReload="true">
<extensions>
<add assembly="NLogExtensions" />
<add assembly="NLog.AzureBlobStorage" />
</extensions>
<targets>
<target xsi:type="ColoredConsole" name="colored_console" />
<target name="console" xsi:type="Console" layout="${longdate}|${message}" />
<target name="file" xsi:type="File" fileName="${basedir}/logs/Debug_${shortdate}.txt" layout="${longdate}|${message}" />
<target xsi:type="AzureAppendBlob" name="Azure" layout="${longdate} ${level:uppercase=true} - ${message}" connectionString="myConnectionString" container="mycontainer" blobName="${date:format=yyyy-MM-dd}.log" />
</targets>
<rules>
<logger name="*" minlevel="Error" writeTo="console,file" />
<logger name="*" minlevel="Trace" writeTo="colored_console" />
<logger name="*" minlevel="Error" writeTo="Azure" />
</rules>
</nlog>

    using System;
using NLog;
using NLog.Fluent;
public partial class ErrorPage : System.Web.UI.Page
{
private static Logger Mysameplelogger = LogManager.GetCurrentClassLogger();
protected void Page_Load(object sender, EventArgs e)
{
LogSample();
}
static void LogSample()
{
Mysameplelogger.Trace("Trace: This is a sample Trace Log");
Mysameplelogger.Debug("Debug: This is a sample Debug Log");
Mysameplelogger.Info("Info: This is a sample Info Log");
Mysameplelogger.Warn("Warn: This is a sample Warn Log");
Mysameplelogger.Error("Error: This is a sample Error Log");
Mysameplelogger.Fatal("Fatal: This is a sample Fatal Error Log");
Mysameplelogger.Info().Message("This is a test Info message '{0}'.", DateTime.Now.Ticks).Property("Test", "InfoWrite").Write();
}
}

0 个答案:

没有答案