Logging Targets in SigningHub

In addition to the default logging inside a NLog file, SigningHub supports logging on three different targets i.e. JSON Format, Event Viewer, and Syslog. 

Each target further has three levels of logging, i.e Info, System, and Debug, where:

  • "Info" provides basic level of logging 
  • "System" provides system level of logging, while 
  • The "Debug" level provides the detailed logging information. 

You may choose these logging levels as per your requirement. Lets discuss the configurations as how to enable logging on each target:

Enable Logging in the JSON Format

By default the JSON format is disabled in SigningHub. You can turn it on and off as required. To enable this:

  1. Go to the SigningHub Installation Directory and open the respective SigningHub module folder (i.e. Admin, Core, API, and Desktop Web), whose logs are required to enable.
  2. Open the "Logs" folder.
  3. Look for the "NLog.txt" file and edit it. 
  4. Within the file content, search the text  <logger name="*" writeTo="jsonLog" minlevel="Info" enabled="false"/> under the <rules> tag, and remove the enabled="false" part from it.
  5. Save the changes and close the "NLog.txt" file. Logging will be enabled in the JSON format.
    Later if you want to disable it, edit the "NLog.txt" file from the same location again and append the enabled="false" part in the same string.


Just like eventLog and sysLog section the jsonLog section is also comment now and need to be uncomment when json logging is enabled.


For more details regarding JSON, see https://github.com/NLog/NLog/wiki/JsonLayout


<!--<target name="jsonlog" xsi:type="asyncwrapper">

      <target xsi:type="file" name="jsonlog1" filename="${basedir}/logs/${app}log.json" keepfileopen="false"

              archivefilename="${basedir}/logs/archive/${app}log_${shortdate}.{#}.log"

              archiveabovesize="50000520" archivenumbering="sequence" archiveevery="day"

              maxarchivefiles="30">

        <layout xsi:type="jsonlayout" excludeproperties="comma-separated list (string)">

          <attribute name="time" layout="${longdate}" />

          <attribute name="level" layout="${level:uppercase=true}" />

          <attribute name="message" layout="${mlayout}" />

        </layout>

      </target>

    </target>-->


Each SigningHub module (i.e. Admin, Core, API, and Desktop Web) has got their own Nlog file. So you need to separately enable it on every Nlog.txt file if you want to enable it for all the modules.



To change the logging level:

  1. Edit the "NLog.txt" file from the same location. 
  2. Search the text  <logger name="*" writeTo="jsonLog" minlevel="Info"> in the file content.
  3. Change the minLevel value being shown inside " " as required, i.e. "Info", "System", or "Debug".
  4. Save the changes and close the "NLog.txt" file.

Enable Logging for Event Viewer

By default logging inside an OS Event Viewer is disabled in SigningHub. You can turn it on and off as required.

There are two steps to enable logging for Event Viewer, i.e.:

  • Create a source in Event Viewer.
  • Tweak the "NLog.txt" file to enable Eventlog in it.

Creating a Source in Event Viewer

Source is created inside the System Registry. It is mandatory, and you need to manually create it as IIS does not have the rights to create it. For this:

  1. Open Run > enter regedit
  2. Go to Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\EventLog\Application
  3. Add NEW Key 4. Name should be the same as given in Source e.g. SHWeb


For more details regarding source creation, see https://github.com/NLog/NLog/issues/1537

Tweaking the "NLog.txt" file

For this:

  1. Go to the SigningHub Installation Directory and open the respective SigningHub module folder (i.e. Admin, Core, API, and Desktop Web), whose logs are required to enable.
  2. Open the "Logs" folder.
  3. Look for the "NLog.txt" file and edit it. 
  4. Un-comment the code snippet as highlighted in the following image.

<!--<target name="eventLog" xsi:type="AsyncWrapper">

      <target xsi:type="EventLog" name="eventLog1" layout="${LMlayout}"

              eventId="${event-properties:EventID}" source="SigningHubWeb" encoding="UTF8"></target>

    </target>-->

  1. Now within the file content, search the text  <logger name="*" writeTo="eventLog" minlevel="Info" enabled="false"/> under the <rules> tag, and remove the enabled="false" part from it.
  2. Save the changes and close the "NLog.txt" file. Logging will be enabled for Event Viewer.
    Later if you want to disable it, edit the "NLog.txt" file from the same location again and append the enabled="false" part in the same string.   


For more details regarding EventLog, see https://github.com/nlog/NLog/wiki/EventLog-target


Each SigningHub module (i.e. Admin, Core, API, and Desktop Web) has got their own Nlog file. So you need to separately enable it on every Nlog.txt file if you want to enable it for all the modules.


To change the logging level:

  1. Edit the "NLog.txt" file from the same location. 
  2. Search the text  <logger name="*" writeTo="eventLog" minlevel="Info"> in the file content.
  3. Change the minLevel value being shown inside " " as required, i.e. "Info", "System", or "Debug".
  4. Save the changes and close the "NLog.txt" file.

Enable Logging for Syslog

You can also push the logs to the Syslog Server. For this the Syslog Server should be installed. By default it is disabled in SigningHub, but you can turn it on and off as required. 


To enable pushing logs on Syslog:

  1. Go to the SigningHub Installation Directory and open the respective SigningHub module folder (i.e. Admin, Core, API, and Desktop Web), whose logs are required to enable.
  2. Open the "Logs" folder.
  3. Look for the "NLog.txt" file and edit it. 
  4. Un-comment the code snippet as highlighted in the following image.

<!--<target xsi:type="syslog" name="sysLog">

      <sl:layout xsi:type="SimpleLayout" text="{&quot;message&quot;: &quot;${message}&quot;}" />

      <sl:messageCreation>

        <sl:facility>Local4</sl:facility>

        <sl:rfc>Rfc5424</sl:rfc>

        <sl:rfc5424>

          <sl:hostname xsi:type="SimpleLayout" text="${machinename}" />

          <sl:appName xsi:type="SimpleLayout" text="" />

          <sl:disableBom>true</sl:disableBom>

        </sl:rfc5424>

      </sl:messageCreation>

      <sl:messageSend>

        <sl:protocol>tcp</sl:protocol>

        <sl:tcp>

          <sl:server>127.0.0.1</sl:server>

          <sl:port>1468</sl:port>

        </sl:tcp>

      </sl:messageSend>

    </target>-->

  1. Now within the file content, search the text  <logger name="*" writeTo="sysLog" minlevel="Info" enabled="false"/> under the <rules> tag, and remove the enabled="false" part from it.
  2. Save the changes and close the "NLog.txt" file. Logging will be enabled for Syslog.
    Later if you want to disable it, edit the "NLog.txt" file from the same location again and append the enabled="false" part in the same string. 

  

For more details regarding Syslog, see https://github.com/luigiberrettini/NLog.Targets.Syslog


Each SigningHub module (i.e. Admin, Core, API, and Desktop Web) has got their own Nlog file. So you need to separately enable it on every Nlog.txt file if you want to enable it for all the modules.


To change the logging level:

  1. Edit the "NLog.txt" file from the same location. 
  2. Search the text  <logger name="*" writeTo="sysLog" minlevel="Info"> in the file content.
  3. Change the minLevel value being shown inside " " as required, i.e. "Info", "System", or "Debug".
  4. Save the changes and close the "NLog.txt" file.

Troubleshooting

Sometimes our application doesn’t write anything to the log files, even though we have supposedly configured logging properly. There can be many reasons for logs not being written. The most common problems are permissions issues, usually in an ASP.NET process, where the aspnet_wp.exe or w3wp.exe process may not have write access to the directory where we want to store logs.


NLog is designed to swallow run-time exceptions that may result from logging. The following settings can change this behavior and/or redirect these messages.


  • <nlog throwExceptions="true" /> - adding the throwExceptions attribute in the config file causes NLog to stop masking exceptions and pass them to the calling application instead. This attribute is useful at deployment time to quickly locate any problems. It is critical that one configure throwExceptions to "false" as soon as the application is properly configured to run, so accidental logging problems will not cause application to hang or crash.
  • <nlog throwConfigExceptions="true" /> - Similar to throwExceptions but isolated to configuration exceptions only. Unlike throwExceptions then it is not dangerous to have enabled, and is recommended for production environments where it is critical that initial setup of logging configuration succeeds. Introduced in NLog 4.3. Default null (Means not configured and instead use value of throwExceptions)
  • <nlog internalLogLevel="Trace|Debug|Info|Warn|Error|Fatal" /> – determines the internal log level. The higher the level, the less verbose the internal log output. The output is usually very helpful when needing to diagnose logging issues. See Internal-logging for options to setup output to File or Console.
  • Set throwExceptions="false" by default.


Add utf-8 inside the target tag when logging using Non-English text is required

    <!--<target name="eventLog" xsi:type="AsyncWrapper">

      <target xsi:type="EventLog" name="eventLog1" layout="${LMlayout}"

              eventId="${event-properties:EventID}" source="SigningHubWeb" encoding="UTF8"></target>

    </target>-->