Skip to content

Logging with Serilog in FhirStarter Deprecated

verzada edited this page Jul 10, 2017 · 1 revision

Logging with Serilog has been deprecated

The reason for this is due to the multitude of packages which Serilog comes with and the fact that settings must be added in the appSettings section instead of a Serilog section in the web / app.config. Making Serilog customizable for any situation is really taxing, and cannot be done at this moment. Instead, we're using log4net which is an easier logging tool to implement.

Setting up logging

The custom Serilog tool looks for settings in the web.config (Refer to the app.config in the FhirStarter.Serilog.UnitTest project to review the latest settings). Mainly exceptions which are transformed to OperationOutcomes are logged by default.

Logging to file

To just log to file, make sure the appSetting

<add key="SerilogFilePath" value="C:\Log\Serilog\application.log"/>

is available in the web.config file. Change the value to your preferred logging directory as well as file name.

Logging to Splunk (todo)

To log to Splunk, make sure the appSettings

    <!-- splunk url -->
    <add key="SerilogSplunkUrl" value=""/>
    <!-- token used with the splunk url-->
    <add key="SplunkEventCollectorToken" value=""/>

are added to the web.config

Logging via TCP or UDP (todo)

To log via TCP or UDP, make sure the appSettings

    <!--Write tcp or udp in the setting-->
    <add key="SerilogSplunkViaTcpOrUdp" value=""/>
    <!-- The port which the tcp or udp connection uses-->
    <add key="SplunkPort" value=""/>
    <!-- The hostname which the tcp or udp connection uses-->
    <add key="SplunkHost" value=""/>

are available

Using Serilog in general

To log more than the default, you can access the customized Serilog tool by initializing the logger:

   var logger = SetupSerilogLogging.GetLogger();
log.Information(<input>)

The only thing the SetupSerilogLogging.GetLogger(); does, is pre configure the logging settings according to the web.config.

The most reliable setting at the moment is the logging to file, as the other options haven't been easy to test due to lack of knowledge when it comes to Splunk setup.