NLog FileTarget Example

Post Reply
RPierre
Posts: 9
Joined: Wed Jul 17, 2019 8:38 pm

NLog FileTarget Example

Post by RPierre » Tue Oct 20, 2020 8:13 pm

How can i do to use a NLOG FileTarget instead of native FileLogger of library? The example in demo.zip shows only consolelog.
alt
Site Admin
Posts: 985
Joined: Tue Apr 25, 2006 9:45 am

Re: NLog FileTarget Example

Post by alt » Tue Oct 20, 2020 8:31 pm

Please have a look at the sample project https://gitlab.com/inetlab/smpp-samples ... ngWithNLog
RPierre
Posts: 9
Joined: Wed Jul 17, 2019 8:38 pm

Re: NLog FileTarget Example

Post by RPierre » Tue Oct 20, 2020 9:27 pm

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>
alt
Site Admin
Posts: 985
Joined: Tue Apr 25, 2006 9:45 am

Re: NLog FileTarget Example

Post by alt » Wed Oct 21, 2020 4:23 pm

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
Post Reply