New: Added UDP syslog support

(cherry picked from commit 8d856b2edb8bf46a2b516d5f7644ae3fa1151323)
pull/1683/head
Robin Dadswell 3 years ago committed by Qstick
parent 16f67265c9
commit 5a7b4d41d8

@ -30,6 +30,7 @@
<PackageVersion Include="Newtonsoft.Json" Version="13.0.1" />
<PackageVersion Include="NLog.Extensions.Logging" Version="1.7.4" />
<PackageVersion Include="NLog" Version="4.7.14" />
<PackageVersion Include="NLog.Targets.Syslog" Version="6.0.2" />
<PackageVersion Include="NUnit3TestAdapter" Version="4.2.1" />
<PackageVersion Include="NUnit" Version="3.13.2" />
<PackageVersion Include="NunitXml.TestLogger" Version="3.0.117" />
@ -60,4 +61,4 @@
<PackageVersion Include="TagLibSharp-Lidarr" Version="2.2.0.19" />
<PackageVersion Include="Unity" Version="5.11.10" />
</ItemGroup>
</Project>
</Project>

@ -44,6 +44,8 @@ namespace NzbDrone.Core.Configuration
bool UpdateAutomatically { get; }
UpdateMechanism UpdateMechanism { get; }
string UpdateScriptPath { get; }
string SyslogServer { get; }
int SyslogPort { get; }
}
public class ConfigFileProvider : IConfigFileProvider
@ -209,6 +211,9 @@ namespace NzbDrone.Core.Configuration
public string UpdateScriptPath => GetValue("UpdateScriptPath", "", false);
public string SyslogServer => GetValue("SyslogServer", "", persist: false);
public int SyslogPort => GetValueInt("SyslogPort", 514, persist: false);
public int GetValueInt(string key, int defaultValue, bool persist = true)
{
return Convert.ToInt32(GetValue(key, defaultValue, persist));

@ -2,6 +2,8 @@ using System.Collections.Generic;
using System.Linq;
using NLog;
using NLog.Config;
using NLog.Targets.Syslog;
using NLog.Targets.Syslog.Settings;
using NzbDrone.Common.EnvironmentInfo;
using NzbDrone.Common.Extensions;
using NzbDrone.Common.Instrumentation;
@ -40,6 +42,11 @@ namespace NzbDrone.Core.Instrumentation
minimumConsoleLogLevel = LogLevel.Info;
}
if (_configFileProvider.SyslogServer.IsNotNullOrWhiteSpace())
{
SetSyslogParameters(_configFileProvider.SyslogServer, _configFileProvider.SyslogPort, minimumLogLevel);
}
var rules = LogManager.Configuration.LoggingRules;
//Console
@ -101,6 +108,24 @@ namespace NzbDrone.Core.Instrumentation
}
}
private void SetSyslogParameters(string syslogServer, int syslogPort, LogLevel minimumLogLevel)
{
var syslogTarget = new SyslogTarget();
syslogTarget.Name = "syslogTarget";
syslogTarget.MessageSend.Protocol = ProtocolType.Udp;
syslogTarget.MessageSend.Udp.Port = syslogPort;
syslogTarget.MessageSend.Udp.Server = syslogServer;
syslogTarget.MessageSend.Udp.ReconnectInterval = 500;
syslogTarget.MessageCreation.Rfc = RfcNumber.Rfc5424;
syslogTarget.MessageCreation.Rfc5424.AppName = BuildInfo.AppName;
var loggingRule = new LoggingRule("*", minimumLogLevel, syslogTarget);
LogManager.Configuration.AddTarget("syslogTarget", syslogTarget);
LogManager.Configuration.LoggingRules.Add(loggingRule);
}
private List<LogLevel> GetLogLevels()
{
return new List<LogLevel>

@ -18,6 +18,7 @@
<PackageReference Include="MailKit" />
<PackageReference Include="Newtonsoft.Json" />
<PackageReference Include="NLog" />
<PackageReference Include="NLog.Targets.Syslog" />
<PackageReference Include="RestSharp" />
<PackageReference Include="System.IO.Abstractions" />
<PackageReference Include="TagLibSharp-Lidarr" />

Loading…
Cancel
Save