2013-01-20 00:19:27 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using Autofac;
|
|
|
|
|
using Autofac.Core;
|
|
|
|
|
using NLog;
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.Instrumentation
|
|
|
|
|
{
|
|
|
|
|
public class LogInjectionModule : Module
|
|
|
|
|
{
|
|
|
|
|
protected override void AttachToComponentRegistration(IComponentRegistry registry, IComponentRegistration registration)
|
|
|
|
|
{
|
|
|
|
|
registration.Preparing += OnComponentPreparing;
|
|
|
|
|
}
|
2013-02-20 02:05:15 +00:00
|
|
|
|
|
2013-01-20 00:19:27 +00:00
|
|
|
|
static void OnComponentPreparing(object sender, PreparingEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
e.Parameters = e.Parameters.Union(new[]
|
|
|
|
|
{
|
|
|
|
|
new ResolvedParameter((p, i) => p.ParameterType == typeof(Logger), (p,i)=> GetLogger(p.Member.DeclaringType))
|
|
|
|
|
});
|
|
|
|
|
}
|
2013-02-20 02:05:15 +00:00
|
|
|
|
|
2013-01-20 00:19:27 +00:00
|
|
|
|
private static object GetLogger(Type type)
|
|
|
|
|
{
|
2013-03-01 00:50:50 +00:00
|
|
|
|
return LogManager.GetLogger(type.Name);
|
2013-01-20 00:19:27 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|