removed logconfiguration

pull/3113/head
kay.one 12 years ago
parent 2fae57dbea
commit 651c7c095a

1
.gitignore vendored

@ -135,3 +135,4 @@ UpdateLogs/
*/test-results/*
.idea/*
NzbDrone.Web/*
*log.txt

@ -71,7 +71,6 @@ namespace NzbDrone.Api
{
EnvironmentProvider.UGuid = container.Resolve<ConfigService>().UGuid;
ReportingService.RestProvider = container.Resolve<RestProvider>();
ReportingService.SetupExceptronDriver();
}
protected override ILifetimeScope GetApplicationContainer()

@ -0,0 +1,21 @@
using System.Linq;
using System.Reflection;
using System.Text;
using NLog;
using NLog.Config;
using NLog.LayoutRenderers;
namespace NzbDrone.Common.Instrumentation
{
[ThreadAgnostic]
[LayoutRenderer("version")]
public class VersionLayoutRenderer : LayoutRenderer
{
private static readonly string version = Assembly.GetExecutingAssembly().GetName().Version.ToString();
protected override void Append(StringBuilder builder, LogEventInfo logEvent)
{
builder.Append(version);
}
}
}

@ -1,101 +0,0 @@
using System;
using NLog;
using NLog.Config;
using NLog.Targets;
using NzbDrone.Common.NlogTargets;
namespace NzbDrone.Common
{
public static class LogConfiguration
{
static LogConfiguration()
{
if (EnvironmentProvider.IsProduction)
{
LogManager.ThrowExceptions = false;
}
else
{
LogManager.ThrowExceptions = true;
}
if (LogManager.Configuration == null)
{
LogManager.Configuration = new LoggingConfiguration();
}
}
private static FileTarget GetBaseTarget()
{
var fileTarget = new FileTarget();
fileTarget.AutoFlush = true;
fileTarget.ConcurrentWrites = true;
fileTarget.KeepFileOpen = false;
fileTarget.ConcurrentWriteAttemptDelay = 50;
fileTarget.ConcurrentWriteAttempts = 200;
fileTarget.Layout = @"${date:format=yy-M-d HH\:mm\:ss.f}|${replace:searchFor=NzbDrone.:replaceWith=:inner=${logger}}|${level}|${message}|${exception:format=ToString}";
return fileTarget;
}
public static void RegisterFileLogger(string fileName, LogLevel level)
{
var fileTarget = GetBaseTarget();
fileTarget.FileName = fileName;
LogManager.Configuration.AddTarget(Guid.NewGuid().ToString(), fileTarget);
LogManager.Configuration.LoggingRules.Add(new LoggingRule("*", level, fileTarget));
}
public static void RegisterRollingFileLogger(string fileName, LogLevel level)
{
var fileTarget = GetBaseTarget();
fileTarget.FileName = fileName;
fileTarget.ArchiveAboveSize = 512000; //500K x 2
fileTarget.MaxArchiveFiles = 1;
fileTarget.EnableFileDelete = true;
fileTarget.ArchiveNumbering = ArchiveNumberingMode.Rolling;
LogManager.Configuration.AddTarget(Guid.NewGuid().ToString(), fileTarget);
LogManager.Configuration.LoggingRules.Add(new LoggingRule("*", level, fileTarget));
}
public static void RegisterRemote()
{
//if (EnviromentProvider.IsProduction)
//{
// try
// {
// var exceptioneerTarget = new ExceptioneerTarget();
// LogManager.Configuration.AddTarget("Exceptioneer", exceptioneerTarget);
// LogManager.Configuration.LoggingRules.Add(new LoggingRule("*", LogLevel.Trace, exceptioneerTarget));
// }
// catch (Exception e)
// {
// Console.WriteLine(e);
// }
//}
try
{
var remoteTarget = new RemoteTarget();
LogManager.Configuration.AddTarget("RemoteTarget", remoteTarget);
LogManager.Configuration.LoggingRules.Add(new LoggingRule("*", LogLevel.Trace, remoteTarget));
}
catch (Exception e)
{
Console.WriteLine(e);
}
LogManager.ConfigurationReloaded += (sender, args) => RegisterRemote();
}
public static void Reload()
{
LogManager.Configuration.Reload();
LogManager.ReconfigExistingLoggers();
}
}
}

@ -1,21 +0,0 @@
using System.Linq;
using System.Diagnostics;
using NLog;
using NLog.Targets;
namespace NzbDrone.Common.NlogTargets
{
public class RemoteTarget : Target
{
private static readonly Logger logger = LogManager.GetCurrentClassLogger();
protected override void Write(LogEventInfo logEvent)
{
if (logEvent == null || logEvent.Exception == null) return;
logger.Trace("Sending Exception to Service.NzbDrone.com . Process Name: {0}", Process.GetCurrentProcess().ProcessName);
ReportingService.ReportException(logEvent);
}
}
}

@ -61,10 +61,6 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Autofac.3.0.1\lib\net40\Autofac.Configuration.dll</HintPath>
</Reference>
<Reference Include="Exceptron.Client, Version=1.0.7.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Exceptron.Client.1.0.7\lib\net20\Exceptron.Client.dll</HintPath>
</Reference>
<Reference Include="Nancy">
<HintPath>..\packages\Nancy.0.16.1\lib\net40\Nancy.dll</HintPath>
</Reference>
@ -115,18 +111,17 @@
<Compile Include="Eventing\IEventAggregator.cs" />
<Compile Include="Eventing\IHandle.cs" />
<Compile Include="HostController.cs" />
<Compile Include="Instrumentation\VersionLayoutRenderer.cs" />
<Compile Include="StringExtention.cs" />
<Compile Include="HttpProvider.cs" />
<Compile Include="ConfigFileProvider.cs" />
<Compile Include="ConsoleProvider.cs" />
<Compile Include="Contract\ReportBase.cs" />
<Compile Include="Contract\ParseErrorReport.cs" />
<Compile Include="NlogTargets\RemoteTarget.cs" />
<Compile Include="Model\AuthenticationType.cs" />
<Compile Include="PathExtentions.cs" />
<Compile Include="DiskProvider.cs" />
<Compile Include="EnvironmentProvider.cs" />
<Compile Include="LogConfiguration.cs" />
<Compile Include="Model\ProcessInfo.cs" />
<Compile Include="ProcessProvider.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />

@ -156,16 +156,6 @@ namespace NzbDrone.Common
return Path.Combine(environmentProvider.GetUpdateSandboxFolder(), UPDATE_LOG_FOLDER_NAME);
}
public static string GetLogFileName(this EnvironmentProvider environmentProvider)
{
return Path.Combine(environmentProvider.ApplicationPath, "nzbdrone.log.txt");
}
public static string GetArchivedLogFileName(this EnvironmentProvider environmentProvider)
{
return Path.Combine(environmentProvider.ApplicationPath, "nzbdrone.log.0.txt");
}
public static string GetConfigBackupFile(this EnvironmentProvider environmentProvider)
{
return Path.Combine(environmentProvider.GetAppDataPath(), BACKUP_ZIP_FILE);

@ -1,8 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Exceptron.Client;
using Exceptron.Client.Configuration;
using NLog;
using NzbDrone.Common.Contract;
@ -16,7 +14,6 @@ namespace NzbDrone.Common
private const string PARSE_URL = SERVICE_URL + "/ParseError";
public static RestProvider RestProvider { get; set; }
public static ExceptronClient ExceptronClient { get; set; }
private static readonly HashSet<string> parserErrorCache = new HashSet<string>();
@ -57,68 +54,6 @@ namespace NzbDrone.Common
}
}
public static string ReportException(LogEventInfo logEvent)
{
try
{
VerifyDependencies();
var exceptionData = new ExceptionData();
exceptionData.Exception = logEvent.Exception;
exceptionData.Component = logEvent.LoggerName;
exceptionData.Message = logEvent.FormattedMessage;
exceptionData.UserId = EnvironmentProvider.UGuid.ToString().Replace("-", string.Empty);
if (logEvent.Level <= LogLevel.Info)
{
exceptionData.Severity = ExceptionSeverity.None;
}
else if (logEvent.Level <= LogLevel.Warn)
{
exceptionData.Severity = ExceptionSeverity.Warning;
}
else if (logEvent.Level <= LogLevel.Error)
{
exceptionData.Severity = ExceptionSeverity.Error;
}
else if (logEvent.Level <= LogLevel.Fatal)
{
exceptionData.Severity = ExceptionSeverity.Fatal;
}
return ExceptronClient.SubmitException(exceptionData).RefId;
}
catch (Exception e)
{
if (!EnvironmentProvider.IsProduction)
{
throw;
}
if (logEvent.LoggerName != logger.Name)//prevents a recursive loop.
{
logger.WarnException("Unable to report exception. ", e);
}
}
return null;
}
public static void SetupExceptronDriver()
{
var config = new ExceptronConfiguration
{
ApiKey = "CB230C312E5C4FF38B4FB9644B05E60G",
ThrowExceptions = !EnvironmentProvider.IsProduction,
};
ExceptronClient = new ExceptronClient(config)
{
ApplicationVersion = new EnvironmentProvider().Version.ToString()
};
}
private static void VerifyDependencies()
{
if (RestProvider == null)
@ -133,19 +68,6 @@ namespace NzbDrone.Common
throw new InvalidOperationException("REST Provider wasn't configured correctly.");
}
}
if (ExceptronClient == null)
{
if (EnvironmentProvider.IsProduction)
{
logger.Warn("Exceptron Driver wasn't provided. creating new one!");
SetupExceptronDriver();
}
else
{
throw new InvalidOperationException("Exceptron Driver wasn't configured correctly.");
}
}
}
}
}

@ -1,7 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Autofac" version="3.0.1" targetFramework="net40" />
<package id="Exceptron.Client" version="1.0.7" targetFramework="net40" />
<package id="Nancy" version="0.16.1" targetFramework="net40" />
<package id="Nancy.Hosting.Self" version="0.16.1" targetFramework="net40" />
<package id="Newtonsoft.Json" version="4.5.11" targetFramework="net40" />

@ -0,0 +1,90 @@
using System;
using System.Linq;
using FizzWare.NBuilder;
using FluentAssertions;
using NUnit.Framework;
using NzbDrone.Core.Datastore;
using NzbDrone.Core.Test.Framework;
namespace NzbDrone.Core.Test.Datastore
{
public class SampleType : ModelBase
{
public string Name { get; set; }
public string Tilte { get; set; }
public string Address { get; set; }
}
[TestFixture]
public class BaiscRepositoryFixture : ObjectDbTest<BasicRepository<SampleType>,SampleType>
{
private SampleType sampleType;
[SetUp]
public void Setup()
{
sampleType = Builder<SampleType>
.CreateNew()
.With(c => c.Id = 0)
.Build();
}
[Test]
public void should_be_able_to_add()
{
Subject.Insert(sampleType);
Subject.All().Should().HaveCount(1);
}
[Test]
public void should_be_able_to_delete_model()
{
Subject.Insert(sampleType);
Subject.All().Should().HaveCount(1);
Subject.Delete(sampleType.Id);
Subject.All().Should().BeEmpty();
}
[Test]
public void should_be_able_to_find_by_id()
{
Subject.Insert(sampleType);
Subject.Get(sampleType.Id)
.ShouldHave()
.AllProperties()
.EqualTo(sampleType);
}
[Test]
public void should_be_able_to_update_existing_model()
{
Subject.Insert(sampleType);
sampleType.Address = "newAddress";
Subject.Update(sampleType);
Subject.Get(sampleType.Id).Address.Should().Be(sampleType.Address);
}
[Test]
public void getting_model_with_invalid_id_should_throw()
{
Assert.Throws<InvalidOperationException>(() => Subject.Get(12));
}
[Test]
public void get_all_with_empty_db_should_return_empty_list()
{
Subject.All().Should().BeEmpty();
}
}
}

@ -22,7 +22,6 @@ namespace NzbDrone.Core.Instrumentation
LogManager.Configuration.LoggingRules.Add(new LoggingRule("*", LogLevel.Info, this));
LogManager.ConfigurationReloaded += (sender, args) => Register();
LogConfiguration.Reload();
}

@ -22,7 +22,6 @@ namespace NzbDrone.Test.Common
LogManager.Configuration.LoggingRules.Add(new LoggingRule("*", consoleTarget));
RegisterExceptionVerification();
LogConfiguration.Reload();
}
}

@ -53,7 +53,6 @@ namespace NzbDrone.Test.Common
MockedRestProvider = new Mock<RestProvider>();
ReportingService.RestProvider = MockedRestProvider.Object;
ReportingService.SetupExceptronDriver();
Directory.CreateDirectory(TempFolder);
}

@ -0,0 +1,15 @@
<?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="File" name="fileLogger" fileName="${date:format=yyyy.MM.dd-H-mm}.txt" autoFlush="true" keepFileOpen="false"
concurrentWrites="false" concurrentWriteAttemptDelay="50" concurrentWriteAttempts ="10"
layout="${date:format=yy-M-d HH\:mm\:ss.f}|${logger}}|${level}|${message}|${exception:format=ToString}"/>
</targets>
<rules>
<logger name="*" minlevel="Debug" writeTo="consoleLogger"/>
<logger name="*" minlevel="Trace" writeTo="udpTarget"/>
<logger name="*" minlevel="Trace" writeTo="rollingFileLogger"/>
</rules>
</nlog>

File diff suppressed because it is too large Load Diff

@ -45,6 +45,13 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Autofac.3.0.1\lib\net40\Autofac.Configuration.dll</HintPath>
</Reference>
<Reference Include="Exceptron.Client, Version=1.0.20.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Exceptron.Client.1.0.20\lib\net20\Exceptron.Client.dll</HintPath>
</Reference>
<Reference Include="Exceptron.NLog">
<HintPath>..\packages\Exceptron.Nlog.1.0.11\lib\net20\Exceptron.NLog.dll</HintPath>
</Reference>
<Reference Include="NLog">
<HintPath>..\packages\NLog.2.0.0.2000\lib\net40\NLog.dll</HintPath>
</Reference>
@ -62,6 +69,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>

@ -31,7 +31,9 @@ namespace NzbDrone.Update
builder.RegisterAssemblyTypes(typeof(UpdateProvider).Assembly).SingleInstance();
builder.RegisterAssemblyTypes(typeof(RestProvider).Assembly).SingleInstance();
_container = builder.Build();
InitLoggers();
ReportingService.RestProvider = _container.Resolve<RestProvider>();
logger.Info("Updating NzbDrone to version {0}", _container.Resolve<EnvironmentProvider>().Version);
_container.Resolve<Program>().Start(args);
@ -59,18 +61,6 @@ namespace NzbDrone.Update
}
}
private static void InitLoggers()
{
ReportingService.RestProvider = _container.Resolve<RestProvider>();
ReportingService.SetupExceptronDriver();
LogConfiguration.RegisterRemote();
var logPath = Path.Combine(new EnvironmentProvider().GetSandboxLogFolder(), DateTime.Now.ToString("yyyy.MM.dd-H-mm") + ".txt");
LogConfiguration.RegisterFileLogger(logPath, LogLevel.Info);
LogConfiguration.Reload();
}
public void Start(string[] args)
{

@ -1,5 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Autofac" version="3.0.1" targetFramework="net40" />
<package id="Exceptron.Client" version="1.0.20" targetFramework="net40" />
<package id="Exceptron.Nlog" version="1.0.11" 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>

@ -2,6 +2,7 @@
<FileVersion>1</FileVersion>
<AutoEnableOnStartup>False</AutoEnableOnStartup>
<AllowParallelTestExecution>true</AllowParallelTestExecution>
<AllowTestsToRunInParallelWithThemselves>true</AllowTestsToRunInParallelWithThemselves>
<FrameworkUtilisationTypeForNUnit>UseDynamicAnalysis</FrameworkUtilisationTypeForNUnit>
<FrameworkUtilisationTypeForGallio>Disabled</FrameworkUtilisationTypeForGallio>
<FrameworkUtilisationTypeForMSpec>Disabled</FrameworkUtilisationTypeForMSpec>

@ -17,7 +17,7 @@ namespace NzbDrone
var builder = new ContainerBuilder();
BindKernel(builder);
container = builder.Build();
InitilizeApp();
InitializeApp();
}
public static IContainer Container
@ -37,16 +37,12 @@ namespace NzbDrone
builder.RegisterAssemblyTypes(Assembly.GetExecutingAssembly());
}
private static void InitilizeApp()
private static void InitializeApp()
{
var environmentProvider = container.Resolve<EnvironmentProvider>();
ReportingService.RestProvider = container.Resolve<RestProvider>();
ReportingService.SetupExceptronDriver();
LogConfiguration.RegisterRollingFileLogger(environmentProvider.GetLogFileName(), LogLevel.Info);
LogConfiguration.RegisterRemote();
LogConfiguration.Reload();
logger.Info("Start-up Path:'{0}'", environmentProvider.ApplicationPath);
}
}

@ -1,6 +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">
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
autoReload="true"
internalLogLevel="Info"
throwExceptions="true"
internalLogToConsole="false"
internalLogToConsoleError="true"
internalLogFile="nlog.txt">
<extensions>
<add assembly="Exceptron.NLog"/>
<add assembly="NzbDrone.Core"/>
<add assembly="NzbDrone.Common"/>
</extensions>
<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">
@ -9,9 +20,16 @@
<layout>${exception:format=ToString}</layout>
</parameter>
</target>
<target xsi:type="File" name="rollingFileLogger" fileName="nzbdrone.log.txt" autoFlush="true" keepFileOpen="false"
concurrentWrites="false" concurrentWriteAttemptDelay="50" concurrentWriteAttempts ="10"
archiveAboveSize="512000" maxArchiveFiles="1" enableFileDelete="true" archiveNumbering ="Rolling"
layout="${date:format=yy-M-d HH\:mm\:ss.f}|${logger}}|${level}|${message}|${exception:format=ToString}"/>
<target xsi:type="Exceptron" name="exceptronTarget" ApiKey="CB230C312E5C4FF38B4FB9644B05E60G" ApplicationVersion="${version}" />
</targets>
<rules>
<logger name="*" minlevel="Debug" writeTo="consoleLogger"/>
<logger name="*" minlevel="Trace" writeTo="udpTarget"/>
<logger name="*" minlevel="Trace" writeTo="rollingFileLogger"/>
<logger name="*" minlevel="Trace" writeTo="exceptronTarget"/>
</rules>
</nlog>

@ -72,11 +72,12 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Autofac.3.0.1\lib\net40\Autofac.Configuration.dll</HintPath>
</Reference>
<Reference Include="EnvDTE, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<EmbedInteropTypes>True</EmbedInteropTypes>
<Reference Include="Exceptron.Client, Version=1.0.20.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Exceptron.Client.1.0.20\lib\net20\Exceptron.Client.dll</HintPath>
</Reference>
<Reference Include="EnvDTE80, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<EmbedInteropTypes>True</EmbedInteropTypes>
<Reference Include="Exceptron.NLog">
<HintPath>..\packages\Exceptron.Nlog.1.0.11\lib\net20\Exceptron.NLog.dll</HintPath>
</Reference>
<Reference Include="Nancy, Version=0.16.1.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>

@ -1,6 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Autofac" version="3.0.1" targetFramework="net40" />
<package id="Exceptron.Client" version="1.0.20" targetFramework="net40" />
<package id="Exceptron.Nlog" version="1.0.11" targetFramework="net40" />
<package id="Nancy" version="0.16.1" targetFramework="net40" />
<package id="Nancy.Bootstrappers.Autofac" version="0.16.1" targetFramework="net40" />
<package id="Nancy.Hosting.Self" version="0.16.1" targetFramework="net40" />

Loading…
Cancel
Save