mirror of
https://github.com/Radarr/Radarr.git
synced 2024-09-11 12:02:35 +02:00
config file based logging configuration.
This commit is contained in:
parent
0f940364a3
commit
c935db93dd
@ -25,57 +25,7 @@ static LogConfiguration()
|
||||
}
|
||||
}
|
||||
|
||||
public static void RegisterConsoleLogger(LogLevel minLevel, string loggerNamePattern = "*")
|
||||
{
|
||||
try
|
||||
{
|
||||
var consoleTarget = new ConsoleTarget();
|
||||
consoleTarget.Layout = "${message} ${exception}";
|
||||
LogManager.Configuration.AddTarget(consoleTarget.GetType().Name, consoleTarget);
|
||||
LogManager.Configuration.LoggingRules.Add(new LoggingRule(loggerNamePattern, minLevel, consoleTarget));
|
||||
|
||||
LogManager.ConfigurationReloaded += (sender, args) => RegisterConsoleLogger(minLevel, loggerNamePattern);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e);
|
||||
|
||||
if (LogManager.ThrowExceptions)
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public static void RegisterUdpLogger()
|
||||
{
|
||||
try
|
||||
{
|
||||
var udpTarget = new NLogViewerTarget();
|
||||
udpTarget.Address = "udp://127.0.0.1:20480";
|
||||
udpTarget.IncludeCallSite = true;
|
||||
udpTarget.IncludeSourceInfo = true;
|
||||
udpTarget.IncludeNLogData = true;
|
||||
udpTarget.IncludeNdc = true;
|
||||
udpTarget.Parameters.Add(new NLogViewerParameterInfo
|
||||
{
|
||||
Name = "Exception",
|
||||
Layout = "${exception:format=ToString}"
|
||||
});
|
||||
|
||||
LogManager.Configuration.AddTarget(udpTarget.GetType().Name, udpTarget);
|
||||
LogManager.Configuration.LoggingRules.Add(new LoggingRule("*", LogLevel.Trace, udpTarget));
|
||||
|
||||
LogManager.ConfigurationReloaded += (sender, args) => RegisterUdpLogger();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e);
|
||||
|
||||
if (LogManager.ThrowExceptions)
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private static FileTarget GetBaseTarget()
|
||||
{
|
||||
var fileTarget = new FileTarget();
|
||||
|
@ -1,5 +1,6 @@
|
||||
using NLog;
|
||||
using NLog.Config;
|
||||
using NLog.Targets;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common;
|
||||
|
||||
@ -15,8 +16,10 @@ protected static void InitLogging()
|
||||
if (LogManager.Configuration == null || LogManager.Configuration is XmlLoggingConfiguration)
|
||||
{
|
||||
LogManager.Configuration = new LoggingConfiguration();
|
||||
LogConfiguration.RegisterConsoleLogger(LogLevel.Trace);
|
||||
LogConfiguration.RegisterUdpLogger();
|
||||
var consoleTarget = new ConsoleTarget();
|
||||
consoleTarget.Layout = "${message} ${exception}";
|
||||
LogManager.Configuration.AddTarget(consoleTarget.GetType().Name, consoleTarget);
|
||||
LogManager.Configuration.LoggingRules.Add(new LoggingRule("*", consoleTarget));
|
||||
|
||||
RegisterExceptionVerification();
|
||||
LogConfiguration.Reload();
|
||||
|
@ -66,9 +66,6 @@ private static void InitLoggers()
|
||||
|
||||
LogConfiguration.RegisterRemote();
|
||||
|
||||
LogConfiguration.RegisterConsoleLogger(LogLevel.Trace);
|
||||
LogConfiguration.RegisterUdpLogger();
|
||||
|
||||
var logPath = Path.Combine(new EnvironmentProvider().GetSandboxLogFolder(), DateTime.Now.ToString("yyyy.MM.dd-H-mm") + ".txt");
|
||||
LogConfiguration.RegisterFileLogger(logPath, LogLevel.Info);
|
||||
|
||||
|
@ -45,8 +45,6 @@ private static void InitilizeApp()
|
||||
ReportingService.SetupExceptronDriver();
|
||||
|
||||
LogConfiguration.RegisterRollingFileLogger(environmentProvider.GetLogFileName(), LogLevel.Info);
|
||||
LogConfiguration.RegisterConsoleLogger(LogLevel.Debug);
|
||||
LogConfiguration.RegisterUdpLogger();
|
||||
LogConfiguration.RegisterRemote();
|
||||
LogConfiguration.Reload();
|
||||
logger.Info("Start-up Path:'{0}'", environmentProvider.ApplicationPath);
|
||||
|
17
NzbDrone/NLog.config
Normal file
17
NzbDrone/NLog.config
Normal file
@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<targets>
|
||||
<target xsi:type="ColoredConsole" name="consoleLogger" layout="[${level}] ${logger}: ${message} ${onexception:inner=${newline}${newline}${exception:format=ToString}${newline}}"/>
|
||||
<target xsi:type="NLogViewer" name="udpTarget" address="udp://127.0.0.1:20480" includeCallSite="true" includeSourceInfo="true" includeNLogData="true" includeNdc="true">
|
||||
<parameter>
|
||||
<name>Exception</name>
|
||||
<layout>${exception:format=ToString}</layout>
|
||||
</parameter>
|
||||
</target>
|
||||
</targets>
|
||||
<rules>
|
||||
<logger name="*" minlevel="Debug" writeTo="consoleLogger"/>
|
||||
<logger name="*" minlevel="Trace" writeTo="udpTarget"/>
|
||||
</rules>
|
||||
</nlog>
|
2585
NzbDrone/NLog.xsd
Normal file
2585
NzbDrone/NLog.xsd
Normal file
File diff suppressed because it is too large
Load Diff
@ -113,6 +113,12 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="app.config" />
|
||||
<Content Include="NLog.config">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<None Include="NLog.xsd">
|
||||
<SubType>Designer</SubType>
|
||||
</None>
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
@ -5,4 +5,6 @@
|
||||
<package id="Nancy.Bootstrappers.Autofac" version="0.16.1" targetFramework="net40" />
|
||||
<package id="Nancy.Hosting.Self" version="0.16.1" targetFramework="net40" />
|
||||
<package id="NLog" version="2.0.0.2000" />
|
||||
<package id="NLog.Config" version="2.0.0.2000" targetFramework="net40" />
|
||||
<package id="NLog.Schema" version="2.0.0.2000" targetFramework="net40" />
|
||||
</packages>
|
Loading…
Reference in New Issue
Block a user