Click here to Skip to main content
15,843,327 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to save my Error logs file on Azure Blob Storage. I am able to store these file on FTP Folder by NLog.config.
What I am doing wrong with my code.

Even Log file creating successfully on Local Machine.


Thanks in Advance

What I have tried:

My Nlog.config file

XML
<?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>





c# Code to Create Log file
C#
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();

	}
}
Posted
Updated 21-May-19 20:10pm
v2

1 solution

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900