Skip to content

Instantly share code, notes, and snippets.

@dsect
Created May 22, 2019 16:42
Show Gist options
  • Select an option

  • Save dsect/08ba9d982ccb0d426324f03cd6527b80 to your computer and use it in GitHub Desktop.

Select an option

Save dsect/08ba9d982ccb0d426324f03cd6527b80 to your computer and use it in GitHub Desktop.
Ninject and Log4Net
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