1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-10-31 07:52:37 +01:00

replaced owin's ITraceOutputFactory to one based on nlog that should work on linux.

This commit is contained in:
Keivan Beigi 2013-08-28 15:08:01 -07:00
parent b75aad1268
commit 9b9e1e20eb
6 changed files with 91 additions and 3 deletions

View File

@ -1,4 +1,5 @@
using Nancy.Bootstrapper;
using System;
using Nancy.Bootstrapper;
using NzbDrone.Api;
using NzbDrone.Api.SignalR;
using NzbDrone.Common.Composition;
@ -6,6 +7,7 @@ using NzbDrone.Common.EnvironmentInfo;
using NzbDrone.Core.Datastore;
using NzbDrone.Core.Organizer;
using NzbDrone.Core.RootFolders;
using NzbDrone.Host.Owin;
namespace NzbDrone.Host
{
@ -24,6 +26,7 @@ namespace NzbDrone.Host
Container.Register(typeof(IBasicRepository<RootFolder>), typeof(BasicRepository<RootFolder>));
Container.Register(typeof(IBasicRepository<NamingConfig>), typeof(BasicRepository<NamingConfig>));
Container.Register(typeof(System.IServiceProvider), typeof(OwinServiceProvider));
Container.Register<INancyBootstrapper, NancyBootstrapper>();
}

View File

@ -122,6 +122,9 @@
<Compile Include="AccessControl\FirewallAdapter.cs" />
<Compile Include="AccessControl\UrlAclAdapter.cs" />
<Compile Include="IUserAlert.cs" />
<Compile Include="Owin\NlogTextWriter.cs" />
<Compile Include="Owin\OwinServiceProvider.cs" />
<Compile Include="Owin\OwinTraceOutputFactory.cs" />
<Compile Include="PlatformValidation.cs" />
<Compile Include="MainAppContainerBuilder.cs" />
<Compile Include="ApplicationModes.cs" />

View File

@ -0,0 +1,41 @@
using System.IO;
using System.Text;
using NLog;
namespace NzbDrone.Host.Owin
{
public class NlogTextWriter : TextWriter
{
private readonly Logger logger = LogManager.GetCurrentClassLogger();
public override Encoding Encoding
{
get
{
return Encoding.Default;
}
}
public override void Write(char value)
{
logger.Trace(value);
}
public override void Write(char[] buffer)
{
logger.Trace(buffer);
}
public override void Write(string value)
{
logger.Trace(value);
}
public override void Write(char[] buffer, int index, int count)
{
logger.Trace(buffer);
}
}
}

View File

@ -14,13 +14,15 @@ namespace NzbDrone.Host.Owin
{
private readonly IConfigFileProvider _configFileProvider;
private readonly IEnumerable<IOwinMiddleWare> _owinMiddleWares;
private readonly IServiceProvider _serviceProvider;
private readonly Logger _logger;
private IDisposable _host;
public OwinHostController(IConfigFileProvider configFileProvider, IEnumerable<IOwinMiddleWare> owinMiddleWares, Logger logger)
public OwinHostController(IConfigFileProvider configFileProvider, IEnumerable<IOwinMiddleWare> owinMiddleWares, IServiceProvider serviceProvider, Logger logger)
{
_configFileProvider = configFileProvider;
_owinMiddleWares = owinMiddleWares;
_serviceProvider = serviceProvider;
_logger = logger;
}
@ -37,7 +39,7 @@ namespace NzbDrone.Host.Owin
_logger.Info("starting server on {0}", url);
_host = WebApp.Start(options, BuildApp);
_host = WebApp.Start(_serviceProvider, options, BuildApp);
}
private void BuildApp(IAppBuilder appBuilder)

View File

@ -0,0 +1,25 @@
using System;
using Microsoft.Owin.Hosting.Services;
using Microsoft.Owin.Hosting.Tracing;
namespace NzbDrone.Host.Owin
{
public class OwinServiceProvider : IServiceProvider
{
private readonly IServiceProvider _defaultProvider;
public OwinServiceProvider()
{
_defaultProvider = ServicesFactory.Create();
}
public object GetService(Type serviceType)
{
if (serviceType == typeof (ITraceOutputFactory))
{
return new OwinTraceOutputFactory();
}
return _defaultProvider.GetService(serviceType);
}
}
}

View File

@ -0,0 +1,14 @@
using System.IO;
using Microsoft.Owin.Hosting.Tracing;
namespace NzbDrone.Host.Owin
{
public class OwinTraceOutputFactory : ITraceOutputFactory
{
public TextWriter Create(string outputFile)
{
return new NlogTextWriter();
}
}
}