New: Added UDP syslog support

pull/591/head
Robin Dadswell 3 years ago committed by Qstick
parent e07ad14e83
commit 8d856b2edb

@ -45,6 +45,8 @@ namespace NzbDrone.Core.Configuration
bool UpdateAutomatically { get; }
UpdateMechanism UpdateMechanism { get; }
string UpdateScriptPath { get; }
string SyslogServer { get; }
int SyslogPort { get; }
}
public class ConfigFileProvider : IConfigFileProvider
@ -213,6 +215,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.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 = "Prowlarr";
var loggingRule = new LoggingRule("*", minimumLogLevel, syslogTarget);
LogManager.Configuration.AddTarget("syslogTarget", syslogTarget);
LogManager.Configuration.LoggingRules.Add(loggingRule);
}
private List<LogLevel> GetLogLevels()
{
return new List<LogLevel>

@ -7,6 +7,7 @@
<PackageReference Include="FluentMigrator.Runner" Version="3.3.1" />
<PackageReference Include="MailKit" Version="2.14.0" />
<PackageReference Include="Microsoft.AspNetCore.WebUtilities" Version="2.2.0" />
<PackageReference Include="NLog.Targets.Syslog" Version="6.0.2" />
<PackageReference Include="System.Memory" Version="4.5.4" />
<PackageReference Include="System.ServiceModel.Syndication" Version="5.0.0" />
<PackageReference Include="FluentMigrator.Runner.SQLite" Version="3.3.1" />

Loading…
Cancel
Save