1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-11-28 08:58:41 +02:00

New: Added UDP syslog support

(cherry picked from commit 8d856b2edb8bf46a2b516d5f7644ae3fa1151323)
This commit is contained in:
Robin Dadswell 2021-09-27 23:30:44 +01:00 committed by Mark McDowall
parent 41a821352e
commit 6c0f22a11e
3 changed files with 38 additions and 2 deletions

View File

@ -7,6 +7,7 @@
<PackageReference Include="DotNet4.SocksProxy" Version="1.4.0.1" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
<PackageReference Include="NLog" Version="4.6.6" />
<PackageReference Include="NLog.Targets.Syslog" Version="6.0.3" />
<PackageReference Include="Sentry" Version="1.2.0" />
<PackageReference Include="SharpZipLib" Version="1.2.0" />
<PackageReference Include="System.Data.SQLite.Core.Servarr" Version="1.0.115.5-18" />

View File

@ -42,6 +42,9 @@ public interface IConfigFileProvider : IHandleAsync<ApplicationStartedEvent>,
bool UpdateAutomatically { get; }
UpdateMechanism UpdateMechanism { get; }
string UpdateScriptPath { get; }
string SyslogServer { get; }
int SyslogPort { get; }
string SyslogLevel { get; }
}
public class ConfigFileProvider : IConfigFileProvider
@ -209,7 +212,14 @@ public string UrlBase
public string UpdateScriptPath => GetValue("UpdateScriptPath", "", false);
public int GetValueInt(string key, int defaultValue)
public string SyslogServer => GetValue("SyslogServer", "", persist: false);
public int SyslogPort => GetValueInt("SyslogPort", 514, persist: false);
public string SyslogLevel => GetValue("SyslogLevel", LogLevel, persist: false).ToLowerInvariant();
public int GetValueInt(string key, int defaultValue, bool persist = true)
{
return Convert.ToInt32(GetValue(key, defaultValue));
}

View File

@ -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.Sentry;
@ -32,6 +34,11 @@ public void Reconfigure()
else
minimumConsoleLogLevel = LogLevel.Info;
if (_configFileProvider.SyslogServer.IsNotNullOrWhiteSpace())
{
SetSyslogParameters(_configFileProvider.SyslogServer, _configFileProvider.SyslogPort, minimumLogLevel);
}
var rules = LogManager.Configuration.LoggingRules;
//Console
@ -81,6 +88,24 @@ private void ReconfigureSentry()
}
}
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>