Advertisement
Guest User

Castle Windsor & Log4Net

a guest
Nov 14th, 2012
282
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.03 KB | None | 0 0
  1. public interface IMyClass
  2.     {
  3.         void Log();
  4.     }
  5.  
  6.     public class MyClass : IMyClass
  7.     {
  8.         private ILogger logger;
  9.  
  10.         public MyClass(ILogger logger)
  11.         {
  12.             this.logger = logger;
  13.         }
  14.  
  15.         public void Log()
  16.         {
  17.             logger.Info("I can log");
  18.         }
  19.     }
  20.  
  21.     public class LoggerInstaller : IWindsorInstaller
  22.     {
  23.         public void Install(IWindsorContainer container, Castle.MicroKernel.SubSystems.Configuration.IConfigurationStore store)
  24.         {
  25.             container.AddFacility<LoggingFacility>(f => f.UseLog4Net());
  26.         }
  27.     }
  28.  
  29.     class Program
  30.     {
  31.         static void Main(string[] args)
  32.         {
  33.             var container = new WindsorContainer().Install(FromAssembly.This());
  34.  
  35.             container.Register(Component.For<IMyClass>()
  36.                 .ImplementedBy<MyClass>()
  37.                 .LifestyleTransient());
  38.  
  39.             var myClass = container.Resolve<IMyClass>();
  40.  
  41.             myClass.Log();            
  42.         }
  43.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement