#16829: Replacing TraceLogger by log4netLogger

--HG--
branch : dev
This commit is contained in:
Andre Rodrigues
2010-12-06 16:25:12 -08:00
parent 8bf1511461
commit 9018bdb02c
8 changed files with 89 additions and 45 deletions

View File

@@ -1,27 +0,0 @@
<system.diagnostics>
<trace autoflush="true"/>
<sources>
<source name="Default" switchValue="Warning">
<listeners>
<add name="OrchardDebugTextLog" />
<add name="WebPageTrace"/>
</listeners>
</source>
<source name="Orchard.Localization" switchValue="Warning">
<listeners>
<add name="OrchardDebugTextLog" />
<add name="WebPageTrace"/>
</listeners>
</source>
<source name="Orchard.Data.SessionLocator" switchValue="Information">
<listeners>
<add name="OrchardDebugTextLog" />
<add name="WebPageTrace"/>
</listeners>
</source>
</sources>
<sharedListeners>
<add name="OrchardDebugTextLog" type="System.Diagnostics.TextWriterTraceListener" initializeData="c:\logs\orchard-debug.txt" />
<add name="WebPageTrace" type="System.Web.WebPageTraceListener, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</sharedListeners>
</system.diagnostics>

View File

@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8" ?>
<log4net>
<root>
<!-- Value of priority may be ALL, DEBUG, INFO, WARN, ERROR, FATAL, OFF -->
<priority value="INFO" />
<appender-ref ref="RollingLogFileAppender" />
</root>
<appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
<file value="App_Data/logs/orchard-debug.txt" />
<appendToFile value="true"/>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%logger - %message%newline" />
</layout>
</appender>
</log4net>

View File

@@ -124,6 +124,7 @@
<Compile Include="Global.asax.cs">
<DependentUpon>Global.asax</DependentUpon>
</Compile>
<Content Include="Config\log4net.config" />
<None Include="Media\web.config" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
@@ -150,11 +151,6 @@
<Name>Orchard.Core</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Content Include="Config\Diagnostics.config">
<SubType>Designer</SubType>
</Content>
</ItemGroup>
<ItemGroup>
<Content Include="Config\Sample.Host.config" />
</ItemGroup>

View File

@@ -13,12 +13,14 @@
<section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor" requirePermission="false" />
<section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor" requirePermission="false" />
</sectionGroup>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" requirePermission="false" />
</configSections>
<appSettings>
<add key="webpages:Enabled" value="false" />
<add key="log4net.Config" value="Config\log4net.config" />
</appSettings>
<system.diagnostics configSource="Config\Diagnostics.config"/>
<system.web.webPages.razor>
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />

View File

@@ -5,8 +5,7 @@ using System.Linq;
using System.Reflection;
using Autofac;
using Autofac.Core;
using Castle.Core.Logging;
using Orchard.Environment;
using Castle.Services.Logging.Log4netIntegration;
using Module = Autofac.Module;
namespace Orchard.Logging {
@@ -21,16 +20,7 @@ namespace Orchard.Logging {
protected override void Load(ContainerBuilder moduleBuilder) {
// by default, use Orchard's logger that delegates to Castle's logger factory
moduleBuilder.RegisterType<CastleLoggerFactory>().As<ILoggerFactory>().InstancePerLifetimeScope();
moduleBuilder.Register<Castle.Core.Logging.ILoggerFactory>(componentContext => {
IHostEnvironment host = componentContext.Resolve<IHostEnvironment>();
if (host.IsFullTrust)
return new TraceLoggerFactory();
return new NullLogFactory();
})
.As<Castle.Core.Logging.ILoggerFactory>()
.InstancePerLifetimeScope();
moduleBuilder.RegisterType<Log4netFactory>().As<Castle.Core.Logging.ILoggerFactory>().InstancePerLifetimeScope();
// call CreateLogger in response to the request for an ILogger implementation
moduleBuilder.Register(CreateLogger).As<ILogger>().InstancePerDependency();

View File

@@ -77,6 +77,9 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\lib\Castle Windsor 2.0\bin\Castle.DynamicProxy2.dll</HintPath>
</Reference>
<Reference Include="Castle.Services.Logging.Log4netIntegration">
<HintPath>..\..\lib\Castle Windsor 2.0\bin\Castle.Services.Logging.Log4netIntegration.dll</HintPath>
</Reference>
<Reference Include="ClaySharp, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\lib\claysharp\ClaySharp.dll</HintPath>
@@ -89,6 +92,10 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\lib\sharpziplib\ICSharpCode.SharpZipLib.dll</HintPath>
</Reference>
<Reference Include="log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=1b44e1d426115821, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\lib\fluentnhibernate\log4net.dll</HintPath>
</Reference>
<Reference Include="Microsoft.CSharp" />
<Reference Include="Microsoft.Web.Infrastructure">
<HintPath>..\..\lib\aspnetmvc\Microsoft.Web.Infrastructure.dll</HintPath>