Skip to content

Custom Logging with NLog

Kyryl Krylov, CPA edited this page Jan 17, 2021 · 3 revisions

To enable custom logging update nlog.config and nlog.targets.config. Both files are located in [AppPath]\Terrasoft.WebApp

NlogFiles

Add the following to nlog.config file:

<logger name="GuidedLearningLogger" writeTo="GuidedLearningAppender" 
        minlevel="Info" final="true" />

Add the following to the nlog.target.config file

<target name="GuidedLearningAppender" xsi:type="File"
	layout="${Date} [${ThreadIdOrName}] ${uppercase:${level}} ${UserName} ${MethodName} - ${Message}"
	fileName="${LogDir}/${LogDay}/GuidedLearning.log" />

To use the logger somewhere in your code

using global::Common.Logging;

namespace SomeNameSpace
{
	class MyCLass
	{
		private static readonly ILog _log = LogManager.GetLogger("GuidedLearningLogger");
	}
}

Academy Related Articles

Clone this wiki locally