lots of different things ;)

This commit is contained in:
kay.one 2011-10-23 22:54:09 -07:00
commit 4ae268b8e5
71 changed files with 526 additions and 1229 deletions

View file

@ -3,6 +3,7 @@ using Ninject;
using NLog;
using NLog.Targets;
using NLog.Targets.Wrappers;
using NzbDrone.Common;
using PetaPoco;
namespace NzbDrone.Core.Instrumentation
@ -18,19 +19,15 @@ namespace NzbDrone.Core.Instrumentation
_database = database;
}
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 = logEvent.UserStackFrame.GetMethod().Name;
log.Logger = logEvent.LoggerName;
if (log.Logger.StartsWith("NzbDrone."))
@ -57,7 +54,6 @@ namespace NzbDrone.Core.Instrumentation
log.Level = logEvent.Level.Name;
_database.Insert(log);
}
}

View file

@ -1,30 +0,0 @@
using System.Diagnostics;
using Exceptioneer.WindowsFormsClient;
using NLog;
using NLog.Targets;
namespace NzbDrone.Core.Instrumentation
{
public class ExceptioneerTarget : Target
{
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
protected override void Write(LogEventInfo logEvent)
{
if (logEvent == null || logEvent.Exception == null) return;
if (Debugger.IsAttached || Process.GetCurrentProcess().ProcessName.Contains("JetBrains")) return;
Logger.Trace("Sending Exception to Exceptioneer. {0}", Process.GetCurrentProcess().ProcessName);
logEvent.Exception.Data.Add("Message", logEvent.Message);
new Client
{
ApiKey = "43BBF60A-EB2A-4C1C-B09E-422ADF637265",
ApplicationName = "NZBDrone",
CurrentException = logEvent.Exception
}.Submit();
}
}
}

View file

@ -1,5 +1,4 @@
using System.Diagnostics;
using System.IO;
using System.IO;
using Ninject;
using NLog;
using NLog.Config;
@ -9,32 +8,27 @@ namespace NzbDrone.Core.Instrumentation
{
public static class LogConfiguration
{
public static void Setup()
{
if (Debugger.IsAttached)
if (Common.EnviromentProvider.IsProduction)
{
LogManager.ThrowExceptions = true;
LogManager.ThrowExceptions = false;
}
LogManager.Configuration = new XmlLoggingConfiguration(Path.Combine(new EnviromentProvider().AppPath, "log.config"),
false);
LogManager.Configuration = new XmlLoggingConfiguration(Path.Combine(new EnviromentProvider().AppPath, "log.config"), false);
LogManager.ConfigurationReloaded += ((s, e) => StartDbLogging());
Common.LogConfiguration.RegisterConsoleLogger(LogLevel.Info, "NzbDrone.Web.MvcApplication");
Common.LogConfiguration.RegisterConsoleLogger(LogLevel.Info, "NzbDrone.Core.CentralDispatch");
LogManager.ConfigurationReloaded += ((s, e) => RegisterDatabaseLogger(CentralDispatch.NinjectKernel.Get<DatabaseTarget>()));
}
public static void StartDbLogging()
public static void RegisterDatabaseLogger(DatabaseTarget databaseTarget)
{
#if DEBUG
#else
var exTarget = new ExceptioneerTarget();
LogManager.Configuration.AddTarget("Exceptioneer", exTarget);
LogManager.Configuration.LoggingRules.Add(new LoggingRule("*", NLog.LogLevel.Error, exTarget));
#endif
var sonicTarget = CentralDispatch.NinjectKernel.Get<DatabaseTarget>();
LogManager.Configuration.AddTarget("DbLogger", sonicTarget);
LogManager.Configuration.LoggingRules.Add(new LoggingRule("*", LogLevel.Debug, sonicTarget));
LogManager.Configuration.Reload();
LogManager.Configuration.AddTarget("DbLogger", databaseTarget);
LogManager.Configuration.LoggingRules.Add(new LoggingRule("*", LogLevel.Debug, databaseTarget));
Common.LogConfiguration.Reload();
}
}
}