Show/Hide Toolbars

You can use the EventLog target in an nlog.config file to write Redbex log messages to the Windows Event log (e.g. if you want to centralize all your logging).

During installation the Setup Program automatically creates an event log source named RedbexApplicationServer that can be used for Redbex event log messages. You may however also create your own event log source if you like. Listing 1 shows an example nlog.config file that writes all log messages to the windows event log of the local machine. Listing 2 shows how you can create your own event log source using the Windows command line tool eventcreate.

<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <targets>
      <target
        name="WindowsEventLogInfo"
        xsi:type="EventLog"
        layout="REDBEX ${longdate} ${message}"
        source="RedbexApplicationServer"
        machineName="."
        eventId="1"/>
    <target name="ColoredConsole" xsi:type="ColoredConsole"/>
  </targets>
  <rules>
    <logger name="*" minlevel="Info" writeTo="WindowsEventLogInfo" />
  </rules>
</nlog>

Listing 1: NLog configuration that writes log messages to the windows event log

C:\Windows\system32>eventcreate /ID 1 /L APPLICATION /T ERROR  /SO RedbexCustomSource /D "This is a custom event that is for Redbex logging"

Listing 2: Creating an event log source

© 2021 AFRY Austria GmbH, www.redbex.com