mirror of
https://github.com/lidarr/lidarr.git
synced 2025-08-14 18:57:39 -07:00
added Logger injection module for Autofac, API boots up.
This commit is contained in:
parent
64a3e1caf0
commit
87f3c6a6c9
10 changed files with 78 additions and 23 deletions
36
NzbDrone.Core/Instrumentation/LogInjectionModule.cs
Normal file
36
NzbDrone.Core/Instrumentation/LogInjectionModule.cs
Normal file
|
@ -0,0 +1,36 @@
|
|||
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;
|
||||
}
|
||||
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))
|
||||
});
|
||||
}
|
||||
|
||||
private static object GetLogger(Type type)
|
||||
{
|
||||
const string STRING_TO_REMOVE = "SyntikX";
|
||||
|
||||
var loggerName = type.FullName;
|
||||
if (loggerName.StartsWith(STRING_TO_REMOVE))
|
||||
{
|
||||
loggerName = loggerName.Substring(STRING_TO_REMOVE.Length + 1);
|
||||
}
|
||||
|
||||
return LogManager.GetLogger(loggerName);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue