From df38aa230759d4073cfd0fd3b5373b22142785a3 Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Tue, 16 Apr 2013 20:20:11 -0700 Subject: [PATCH] fixed issue where method names weren't being logged to database. --- NzbDrone.Core/Instrumentation/DatabaseTarget.cs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/NzbDrone.Core/Instrumentation/DatabaseTarget.cs b/NzbDrone.Core/Instrumentation/DatabaseTarget.cs index 8dc00809e..98c8c376b 100644 --- a/NzbDrone.Core/Instrumentation/DatabaseTarget.cs +++ b/NzbDrone.Core/Instrumentation/DatabaseTarget.cs @@ -1,13 +1,14 @@ using System; using NLog.Config; using NLog; +using NLog.Layouts; using NLog.Targets; using NzbDrone.Common; namespace NzbDrone.Core.Instrumentation { - public class DatabaseTarget : Target + public class DatabaseTarget : TargetWithLayout { private readonly ILogRepository _repository; @@ -18,23 +19,20 @@ namespace NzbDrone.Core.Instrumentation public void Register() { + Layout = new SimpleLayout("${callsite:className=false:fileName=false:includeSourcePath=false:methodName=true}"); + LogManager.Configuration.AddTarget("DbLogger", this); LogManager.Configuration.LoggingRules.Add(new LoggingRule("*", LogLevel.Info, this)); - LogManager.ConfigurationReloaded += (sender, args) => Register(); } - + protected override void Write(LogEventInfo logEvent) { var log = new Log(); log.Time = logEvent.TimeStamp; log.Message = logEvent.FormattedMessage; - - if (logEvent.UserStackFrame != null) - { - log.Method = logEvent.UserStackFrame.GetMethod().Name; - } + log.Method = Layout.Render(logEvent); log.Logger = logEvent.LoggerName;