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 Reply
  • hi  ,

    thanks for your reply.

    I have tried, but seems that I cannot write into the JobGenLog logger.

    my code has this

    Dim logJobGenLog = NLog.LogManager.GetLogger("JobGenLog")
    logJobGenLog.Debug("This is a simple log, level (Debug), logger (JobGenLog)")

    and the XML is this

    <nlog autoReload="true" xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    	<targets>
    		<target name="customDebug" xsi:type="File" fileName="C:\CustomDebug\customDebug.log" layout="${longdate} ${level:upperCase=true} (${logger}) : ${event-context:item=Indention}${message} ${exception}" encoding="utf-8" />
    	</targets>
    
    	<rules>
    		<logger name="JobGenLog" minlevel="Debug" writeTo="customDebug"/>
    		<logger name="CCC*" minlevel="Debug" writeTo="customDebug"/>
    	</rules>
    </nlog>

    I have also tried with a custom logger, "CCC_Test", I manage to write in a new file, but not in the sametarget "customDebug".
    Any idea perhaps? Slight smile

Children