mirror of
https://github.com/lidarr/lidarr.git
synced 2025-08-20 21:43:33 -07:00
lots of different things ;)
This commit is contained in:
parent
c42518b34e
commit
4ae268b8e5
71 changed files with 526 additions and 1229 deletions
93
NzbDrone.Common/LogConfiguration.cs
Normal file
93
NzbDrone.Common/LogConfiguration.cs
Normal file
|
@ -0,0 +1,93 @@
|
|||
using System;
|
||||
using System.Diagnostics;
|
||||
using NLog;
|
||||
using NLog.Config;
|
||||
using NLog.Targets;
|
||||
|
||||
namespace NzbDrone.Common
|
||||
{
|
||||
public static class LogConfiguration
|
||||
{
|
||||
static LogConfiguration()
|
||||
{
|
||||
if (EnviromentProvider.IsProduction)
|
||||
{
|
||||
LogManager.ThrowExceptions = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
LogManager.ThrowExceptions = true;
|
||||
}
|
||||
|
||||
if (LogManager.Configuration == null)
|
||||
{
|
||||
LogManager.Configuration = new LoggingConfiguration();
|
||||
}
|
||||
}
|
||||
|
||||
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));
|
||||
Reload();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e);
|
||||
|
||||
if (LogManager.ThrowExceptions)
|
||||
throw;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void RegisterUdpLogger()
|
||||
{
|
||||
try
|
||||
{
|
||||
var udpTarget = new ChainsawTarget();
|
||||
udpTarget.Address = "udp://127.0.0.1:20480";
|
||||
udpTarget.IncludeCallSite = true;
|
||||
udpTarget.IncludeSourceInfo = true;
|
||||
udpTarget.IncludeNLogData = true;
|
||||
udpTarget.IncludeNdc = true;
|
||||
LogManager.Configuration.AddTarget(udpTarget.GetType().Name, udpTarget);
|
||||
LogManager.Configuration.LoggingRules.Add(new LoggingRule("*", LogLevel.Trace, udpTarget));
|
||||
Reload();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e);
|
||||
|
||||
if (LogManager.ThrowExceptions)
|
||||
throw;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void RegisterExceptioneer()
|
||||
{
|
||||
try
|
||||
{
|
||||
var exTarget = new ExceptioneerTarget();
|
||||
LogManager.Configuration.AddTarget("Exceptioneer", exTarget);
|
||||
LogManager.Configuration.LoggingRules.Add(new LoggingRule("*", LogLevel.Error, exTarget));
|
||||
Reload();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static void Reload()
|
||||
{
|
||||
LogManager.Configuration.Reload();
|
||||
LogManager.ReconfigExistingLoggers();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue