Logging using NLog.Logger

Hello Community,

I am trying to improve our logging and I have found that NLog.Logger is a really great framework,

but somehow I can't see the logs created by the scripts (VB.NET Code) called by the processes.

Is there something I am missing here?

My code from an external custom script

Dim log As NLog.Logger = LogManager.GetLogger(LogNames.JobGenLog)
log.Debug("Log entry from JobGenLog logger")

globallog.config

<nlog autoReload="true" xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
	<targets>
		<default-wrapper xsi:type="AsyncWrapper" batchSize="1000" overflowAction="Block" timeToSleepBetweenBatches="0" />
		<target name="jobgenlogfileTmp" xsi:type="File" fileName="C:/OneIdentity/Log/${appName}_jobgen.log" layout="${layout}" encoding="utf-8"
			archiveFileName="C:/OneIdentity/Log/${appName}_jobgen.{#}.log" maxArchiveFiles="7" archiveEvery="Day" archiveNumbering="Rolling"/>		
	</targets>

	<rules>
		<logger name="JobGenLog" minlevel="Debug" writeTo="jobgenlogfileTmp"/>
	</rules>
</nlog>

I am able to see the generated logs by the processes, but not by the VB.Net custom scripts that the process is calling.

Any hints where or what to check?

Thank you!

Parents
  • Hi,

    These are my notes for creating/using a custom NLog logger ..... perhaps it helps.  Personally, I wouldn't use one of the OOB logger configurations ..... just to be in control.

    Add an NLOG logger

    In the globallog.config (on all jobservers):

    Add a target with your custom name:

     <targets>

      <target name="CCC_DataImport" xsi:type="File" fileName="${logBaseDir}/${appName}_CCC_DataImport.log" layout="${layout}" encoding="utf-8"
       archiveFileName="${logBaseDir}/${appName}_CCC_DataImport.{#}.log" maxArchiveFiles="7" archiveEvery="Day" archiveNumbering="Rolling"/>

    Then add a rule:

     <rules>

      <logger name="CCC_DataImport.*" minlevel="Trace" writeTo="CCC_DataImport"/>

    Now in your code:

    ' NLog configuration

    Dim logger As NLog.Logger = NLog.LogManager.GetLogger("CCC_DataImport.CCC_MyScriptName")

    logger.Info("Function Started: {0}", "CCC_MyScriptName")

    HTH, Barry.

Reply
  • Hi,

    These are my notes for creating/using a custom NLog logger ..... perhaps it helps.  Personally, I wouldn't use one of the OOB logger configurations ..... just to be in control.

    Add an NLOG logger

    In the globallog.config (on all jobservers):

    Add a target with your custom name:

     <targets>

      <target name="CCC_DataImport" xsi:type="File" fileName="${logBaseDir}/${appName}_CCC_DataImport.log" layout="${layout}" encoding="utf-8"
       archiveFileName="${logBaseDir}/${appName}_CCC_DataImport.{#}.log" maxArchiveFiles="7" archiveEvery="Day" archiveNumbering="Rolling"/>

    Then add a rule:

     <rules>

      <logger name="CCC_DataImport.*" minlevel="Trace" writeTo="CCC_DataImport"/>

    Now in your code:

    ' NLog configuration

    Dim logger As NLog.Logger = NLog.LogManager.GetLogger("CCC_DataImport.CCC_MyScriptName")

    logger.Info("Function Started: {0}", "CCC_MyScriptName")

    HTH, Barry.

Children
No Data