1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-09 04:22:30 +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;
using NzbDrone.Api.SignalR; using NzbDrone.Api.SignalR;
using NzbDrone.Common.Composition; using NzbDrone.Common.Composition;
@ -6,6 +7,7 @@
using NzbDrone.Core.Datastore; using NzbDrone.Core.Datastore;
using NzbDrone.Core.Organizer; using NzbDrone.Core.Organizer;
using NzbDrone.Core.RootFolders; using NzbDrone.Core.RootFolders;
using NzbDrone.Host.Owin;
namespace NzbDrone.Host namespace NzbDrone.Host
{ {
@ -24,6 +26,7 @@ private MainAppContainerBuilder(StartupArguments args)
Container.Register(typeof(IBasicRepository<RootFolder>), typeof(BasicRepository<RootFolder>)); Container.Register(typeof(IBasicRepository<RootFolder>), typeof(BasicRepository<RootFolder>));
Container.Register(typeof(IBasicRepository<NamingConfig>), typeof(BasicRepository<NamingConfig>)); Container.Register(typeof(IBasicRepository<NamingConfig>), typeof(BasicRepository<NamingConfig>));
Container.Register(typeof(System.IServiceProvider), typeof(OwinServiceProvider));
Container.Register<INancyBootstrapper, NancyBootstrapper>(); Container.Register<INancyBootstrapper, NancyBootstrapper>();
} }

View File

@ -122,6 +122,9 @@
<Compile Include="AccessControl\FirewallAdapter.cs" /> <Compile Include="AccessControl\FirewallAdapter.cs" />
<Compile Include="AccessControl\UrlAclAdapter.cs" /> <Compile Include="AccessControl\UrlAclAdapter.cs" />
<Compile Include="IUserAlert.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="PlatformValidation.cs" />
<Compile Include="MainAppContainerBuilder.cs" /> <Compile Include="MainAppContainerBuilder.cs" />
<Compile Include="ApplicationModes.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 @@ public class OwinHostController : IHostController
{ {
private readonly IConfigFileProvider _configFileProvider; private readonly IConfigFileProvider _configFileProvider;
private readonly IEnumerable<IOwinMiddleWare> _owinMiddleWares; private readonly IEnumerable<IOwinMiddleWare> _owinMiddleWares;
private readonly IServiceProvider _serviceProvider;
private readonly Logger _logger; private readonly Logger _logger;
private IDisposable _host; 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; _configFileProvider = configFileProvider;
_owinMiddleWares = owinMiddleWares; _owinMiddleWares = owinMiddleWares;
_serviceProvider = serviceProvider;
_logger = logger; _logger = logger;
} }
@ -37,7 +39,7 @@ public void StartServer()
_logger.Info("starting server on {0}", url); _logger.Info("starting server on {0}", url);
_host = WebApp.Start(options, BuildApp); _host = WebApp.Start(_serviceProvider, options, BuildApp);
} }
private void BuildApp(IAppBuilder appBuilder) 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();
}
}
}