以下是我的代码。使用Logger对象时出现NullReference
异常。我错过了什么?
using Castle.Core.Logging;
using Castle.Facilities.Logging;
using Castle.MicroKernel.Registration;
using Castle.MicroKernel.SubSystems.Configuration;
using Castle.Windsor;
using Castle.Windsor.Installer;
namespace log4netTest
{
internal class Program
{
private static void Main(string[] args)
{
new WindsorContainer()
.Install(FromAssembly.This());
var test = new testClass();
test.Do();
}
}
public class testClass
{
public ILogger Logger { get; set; }
public void Do()
{
Logger.Info("start");
Logger.Error("error end");
}
}
public class MyWindorInstaller : IWindsorInstaller
{
#region IWindsorInstaller Members
public void Install(IWindsorContainer container, IConfigurationStore store)
{
container.AddFacility<LoggingFacility>(facility => facility.UseLog4Net("log4net.config"));
}
#endregion
}
}
答案 0 :(得分:0)
我应该使用
var test = container.Resolve<testClass>();