Created
May 22, 2019 16:42
-
-
Save dsect/08ba9d982ccb0d426324f03cd6527b80 to your computer and use it in GitHub Desktop.
Ninject and Log4Net
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using System.IO; | |
| using log4net; | |
| using Ninject.Modules; | |
| namespace NinjectSample | |
| { | |
| public class NinjectBindings : NinjectModule | |
| { | |
| public override void Load() | |
| { | |
| Bind<ILog>().ToMethod(context => | |
| { | |
| ThreadContext.Properties["machineName"] = Environment.MachineName; | |
| log4net.Config.XmlConfigurator.ConfigureAndWatch( | |
| new FileInfo(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "log4net.config"))); | |
| return LogManager.GetLogger(context.Request.Target == null | |
| ? typeof(ILog) | |
| : context.Request.Target.Member.DeclaringType); | |
| } | |
| ); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment