Page 1 of 1

NLog FileTarget Example

Posted: Tue Oct 20, 2020 8:13 pm
by RPierre
How can i do to use a NLOG FileTarget instead of native FileLogger of library? The example in demo.zip shows only consolelog.

Re: NLog FileTarget Example

Posted: Tue Oct 20, 2020 8:31 pm
by alt
Please have a look at the sample project https://gitlab.com/inetlab/smpp-samples ... ngWithNLog

Re: NLog FileTarget Example

Posted: Tue Oct 20, 2020 9:27 pm
by RPierre
alt wrote:
Tue Oct 20, 2020 8:31 pm
Please have a look at the sample project https://gitlab.com/inetlab/smpp-samples ... ngWithNLog
I tryed to convert that sample with consolelog demo to work with filetarget but it does not work

when i start the server that call the public class NLogLoggerFactory with loggerName "SmppServer1" instead of "logSMPP"

========= My Code =========

Dim configuration As New LoggingConfiguration()
Dim fileTarget As Target = NLog.LogManager.Configuration.FindTargetByName("logSMPP")

configuration.AddTarget(fileTarget)

NLog.LogManager.Configuration = configuration

LogManager.SetLoggerFactory(New NLogLoggerFactory())

========= My Nlog.config ===========

<rules>
<logger name="logSMPP" minlevel="Trace" writeTo="logSMPP" />
</rules>

<targets async="true" >
<target xsi:type="File" name="logSMPP" fileName="C:\LOG\${shortdate}.log"
layout="${longdate} ${uppercase:${level}} ${message}" />
</targets>

Re: NLog FileTarget Example

Posted: Wed Oct 21, 2020 4:23 pm
by alt
I think you can tell NLog to write all log events for SmppServer this way:

<logger name="SmppServer*" minlevel="Trace" writeTo="logSMPP" />

The logger name for the library instances you can change with properties SmppServer.Name or SmppClient.Name