0

下面是我的代码。NullReference使用 Logger 对象时出现异常。我想念什么?

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
    }
}
4

1 回答 1

0

我应该使用

var test = container.Resolve<testClass>();
于 2012-10-29T07:31:00.900 回答