Search code examples
c#asp.net-core.net-coretls1.2syslog

How to send logs using SYSLOG and TLS from a windows service?


I am creating a Windows Service that will be sending logs to a remote server using SYSLOG. This server requires the logs to be sendt using TLS.

I am currently using Microsoft.Extensions.Logging.Log4Net.AspNetCore(Log4Net) to achieve this. But it seems log4net's RemoteSyslogAppender does not support TLS(RFC5425).

<?xml version="1.0" encoding="utf-8"?>
<log4net debug="true" threshold="ALL">
  <!-- Doc: http://logging.apache.org/log4net/release/sdk/index.html -->
  <!-- From Xml-Schemas, add Common\ConfigAndInfo\log4net.xsd -->
  <appender name="SYSLOG" type="log4net.Appender.RemoteSyslogAppender">
    <remoteAddress value="%env{SYSLOG_URL}" />
    <remotePort value="514" />
    <appName>Application</appName>
    <layout type="log4net.Layout.PatternLayout">
      <conversionPattern value="%message%newline"/>
    </layout>
  </appender>

  <root>
    <level value="ALL" />
    <appender-ref ref="SYSLOG" />
  </root>

</log4net>

I've seen a Nuget package(https://www.nuget.org/packages/syslog4net/) that adds TLS support, but it hasn't been updated since 2017. So I am a bit hesitant to use that.

Anyone found a solution to this? Seems like log4net is the goto library for logging in .NET? Strange that it doesn't support something as common as TLS?


Solution

  • Serilog with the Syslog sink did the trick!