mirror of
https://github.com/lidarr/lidarr.git
synced 2025-08-20 21:43:33 -07:00
added loggly integration
This commit is contained in:
parent
0e7ca07e02
commit
3010ed6073
7 changed files with 211 additions and 1 deletions
70
NzbDrone.Common/Instrumentation/LogglyTarget.cs
Normal file
70
NzbDrone.Common/Instrumentation/LogglyTarget.cs
Normal file
|
@ -0,0 +1,70 @@
|
|||
using System.Collections.Generic;
|
||||
using NLog;
|
||||
using NLog.Config;
|
||||
using NLog.Layouts;
|
||||
using NLog.Targets;
|
||||
using NzbDrone.Common.Serializer;
|
||||
using Logger = Loggly.Logger;
|
||||
|
||||
namespace NzbDrone.Common.Instrumentation
|
||||
{
|
||||
public class LogglyTarget : TargetWithLayout
|
||||
{
|
||||
private readonly IEnvironmentProvider _environmentProvider;
|
||||
private Logger _logger;
|
||||
|
||||
public void Register(LogLevel minLevel)
|
||||
{
|
||||
Layout = new SimpleLayout("${callsite:className=false:fileName=false:includeSourcePath=false:methodName=true}");
|
||||
|
||||
var rule = new LoggingRule("*", minLevel, this);
|
||||
|
||||
LogManager.Configuration.AddTarget("LogglyLogger", this);
|
||||
LogManager.Configuration.LoggingRules.Add(rule);
|
||||
LogManager.ConfigurationReloaded += (sender, args) => Register(minLevel);
|
||||
LogManager.ReconfigExistingLoggers();
|
||||
}
|
||||
|
||||
public LogglyTarget(IEnvironmentProvider environmentProvider)
|
||||
{
|
||||
_environmentProvider = environmentProvider;
|
||||
}
|
||||
|
||||
protected override void InitializeTarget()
|
||||
{
|
||||
string apiKey = string.Empty;
|
||||
|
||||
if (EnvironmentProvider.IsProduction)
|
||||
{
|
||||
apiKey = "4c4ecb69-d1b9-4e2a-b54b-b0c4cc143a95";
|
||||
}
|
||||
else
|
||||
{
|
||||
apiKey = "d344a321-b107-45c4-a548-77138f446510";
|
||||
}
|
||||
|
||||
_logger = new Logger(apiKey);
|
||||
}
|
||||
|
||||
|
||||
protected override void Write(NLog.LogEventInfo logEvent)
|
||||
{
|
||||
var dictionary = new Dictionary<string, object>();
|
||||
|
||||
if (logEvent.Exception != null)
|
||||
{
|
||||
dictionary.Add("ex", logEvent.Exception.ToString());
|
||||
dictionary.Add("extyp", logEvent.Exception.GetType().Name);
|
||||
dictionary.Add("hash", logEvent.GetHash());
|
||||
}
|
||||
|
||||
dictionary.Add("logger", logEvent.LoggerName);
|
||||
dictionary.Add("method", Layout.Render(logEvent));
|
||||
dictionary.Add("level", logEvent.Level.Name);
|
||||
dictionary.Add("message", logEvent.GetFormattedMessage());
|
||||
dictionary.Add("ver", _environmentProvider.Version.ToString());
|
||||
|
||||
_logger.Log(Json.Serialize(dictionary));
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue