made logging configurable via web.config

This commit is contained in:
tmont 2011-03-01 07:13:57 +00:00
parent b1056e079d
commit d08b91c9aa
6 changed files with 37 additions and 16 deletions

View File

@ -46,9 +46,6 @@
<Reference Include="NHibernate.ByteCode.LinFu"> <Reference Include="NHibernate.ByteCode.LinFu">
<HintPath>..\..\Lib\NHibernate.ByteCode.LinFu.dll</HintPath> <HintPath>..\..\Lib\NHibernate.ByteCode.LinFu.dll</HintPath>
</Reference> </Reference>
<Reference Include="NHibernate.Linq">
<HintPath>..\..\Lib\NHibernate.Linq.dll</HintPath>
</Reference>
<Reference Include="Portoa"> <Reference Include="Portoa">
<HintPath>..\..\Lib\Portoa.dll</HintPath> <HintPath>..\..\Lib\Portoa.dll</HintPath>
</Reference> </Reference>

View File

@ -0,0 +1,17 @@
using Microsoft.Practices.Unity;
using Portoa.Web.Unity;
namespace VideoGameQuotes.Web.Configuration {
/// <summary>
/// Enables application-wide logging using log4net
/// </summary>
public class EnableLogging : UnityContainerExtension {
protected override void Initialize() {
Container
.AddNewExtension<ConfigureLog4Net>()
.Configure<ILog4NetConfigurator>()
.SetName("vgquotes")
.UseXml();
}
}
}

View File

@ -20,7 +20,6 @@ using Directory = Lucene.Net.Store.Directory;
using Version = Lucene.Net.Util.Version; using Version = Lucene.Net.Util.Version;
namespace VideoGameQuotes.Web.Configuration { namespace VideoGameQuotes.Web.Configuration {
public class EnableSearchWithLucene : UnityContainerExtension { public class EnableSearchWithLucene : UnityContainerExtension {
protected override void Initialize() { protected override void Initialize() {
var indexWriterLifetimeManager = new ExplicitlyDisposableLifetimeManager<IndexWriter>( var indexWriterLifetimeManager = new ExplicitlyDisposableLifetimeManager<IndexWriter>(

View File

@ -10,7 +10,6 @@ using Portoa.Web.Unity;
using UnityGenerics; using UnityGenerics;
using VideoGameQuotes.Api; using VideoGameQuotes.Api;
using VideoGameQuotes.Api.Persistence; using VideoGameQuotes.Api.Persistence;
using VideoGameQuotes.Web.Configuration;
using VideoGameQuotes.Web.Controllers; using VideoGameQuotes.Web.Controllers;
using VideoGameQuotes.Web.Models; using VideoGameQuotes.Web.Models;
using VideoGameQuotes.Web.Security; using VideoGameQuotes.Web.Security;
@ -26,12 +25,6 @@ namespace VideoGameQuotes.Web {
} }
protected override void ConfigureUnity() { protected override void ConfigureUnity() {
Container
.AddNewExtension<ConfigureLog4Net>()
.Configure<ILog4NetConfigurator>()
.SetName("VideoGameQuotes.Web")
.UseXml();
Container Container
.RegisterType<VerifyUserAttribute>(new InjectionProperty<VerifyUserAttribute>(attr => attr.UserProvider)) .RegisterType<VerifyUserAttribute>(new InjectionProperty<VerifyUserAttribute>(attr => attr.UserProvider))
.RegisterAndIntercept<ICurrentUserProvider<User>, SessionBasedUserProvider>() .RegisterAndIntercept<ICurrentUserProvider<User>, SessionBasedUserProvider>()
@ -44,9 +37,7 @@ namespace VideoGameQuotes.Web {
.RegisterAndIntercept<IGameService, GameService>() .RegisterAndIntercept<IGameService, GameService>()
.RegisterAndIntercept<IApiService, ApiService>() .RegisterAndIntercept<IApiService, ApiService>()
.RegisterAndIntercept<IAuthenticationService, FormsAuthenticationService>() .RegisterAndIntercept<IAuthenticationService, FormsAuthenticationService>()
.RegisterAndIntercept<IUserRepository, UserRepository>() .RegisterAndIntercept<IUserRepository, UserRepository>();
.AddNewExtension<LogAllMethodCalls>()
.AddNewExtension<EnableSearchWithLucene>();
} }
protected override void AfterStartUp() { protected override void AfterStartUp() {

View File

@ -44,6 +44,10 @@
<SpecificVersion>False</SpecificVersion> <SpecificVersion>False</SpecificVersion>
<HintPath>..\..\Lib\Microsoft.Practices.Unity.Interception.dll</HintPath> <HintPath>..\..\Lib\Microsoft.Practices.Unity.Interception.dll</HintPath>
</Reference> </Reference>
<Reference Include="NHibernate.ByteCode.LinFu, Version=3.0.0.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\Lib\NHibernate.ByteCode.LinFu.dll</HintPath>
</Reference>
<Reference Include="Portoa, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL"> <Reference Include="Portoa, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion> <SpecificVersion>False</SpecificVersion>
<HintPath>..\..\Lib\Portoa.dll</HintPath> <HintPath>..\..\Lib\Portoa.dll</HintPath>
@ -85,6 +89,7 @@
</Reference> </Reference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Configuration\EnableLogging.cs" />
<Compile Include="Configuration\EnableSearchWithLucene.cs" /> <Compile Include="Configuration\EnableSearchWithLucene.cs" />
<Compile Include="Configuration\UpdateSearchIndexCallHandler.cs" /> <Compile Include="Configuration\UpdateSearchIndexCallHandler.cs" />
<Compile Include="Controllers\AdminController.cs" /> <Compile Include="Controllers\AdminController.cs" />

View File

@ -2,11 +2,23 @@
<configuration> <configuration>
<configSections> <configSections>
<!--<section name="unity" type="Microsoft.Practices.Unity.Configuration.UnityConfigurationSection"/>--> <section name="unity" type="Microsoft.Practices.Unity.Configuration.UnityConfigurationSection"/>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/> <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
<section name="vgquotes" type="System.Configuration.NameValueSectionHandler"/> <section name="vgquotes" type="System.Configuration.NameValueSectionHandler"/>
</configSections> </configSections>
<unity>
<containers>
<container>
<extensions>
<add type="VideoGameQuotes.Web.Configuration.EnableLogging, VideoGameQuotes.Web"/>
<add type="Portoa.Web.Unity.LogAllMethodCalls, Portoa.Web"/>
<add type="VideoGameQuotes.Web.Configuration.EnableSearchWithLucene, VideoGameQuotes.Web"/>
</extensions>
</container>
</containers>
</unity>
<vgquotes> <vgquotes>
<add key="luceneIndexDirectory" value="c:\users\tmont\code\VideoGameQuotes\lucene_index"/> <add key="luceneIndexDirectory" value="c:\users\tmont\code\VideoGameQuotes\lucene_index"/>
</vgquotes> </vgquotes>
@ -25,7 +37,7 @@
</layout> </layout>
</appender> </appender>
<logger name="VideoGameQuotes.Web"> <logger name="vgquotes">
<level value="ALL"/> <level value="ALL"/>
<appender-ref ref="DebugAppender" /> <appender-ref ref="DebugAppender" />
<appender-ref ref="TelnetAppender" /> <appender-ref ref="TelnetAppender" />