I am abstracting away NLog. So far, what I have...
public interface IAppLogger
{
void Info(string message);
void Warn(string message);
void Error(string message, Exception error);
void Fatal(string message);
....// other overload
}
And an Implementation of IAppLogger using NLog
public class NLogLogger : IAppLogger
{
private readonly NLog.Logger _logger;
public NLogLogger([CallerFilePath] string callerFilePath = "")
{
_logger = NLog.LogManager.GetLogger(callerFilePath);
}
public void Info(string message)
{
_logger.Info(message);
}
public void Warn(string message)
{
_logger.Warn(message);
}
.....// and others
}
And Console Application that uses this service
public class Program
{
private static IAppLogger Log { get; set; }
private static void Main()
{
var kernel = new StandardKernel();
kernel.Load(Assembly.GetExecutingAssembly());
Log = kernel.Get<IAppLogger>();
Log.Info("Application Started");
Log.Warn("Developer: Invalid date format");
Log.Error("Divid by zero error", new DivideByZeroException());
Console.WriteLine("\nDone Logging");
Console.ReadLine();
}
}
And a dependency Injection using Ninject
public class NinjectConfig : NinjectModule
{
public override void Load()
{
Bind<IAppLogger>().To<NLogLogger>()
.WithConstructorArgument("callerFilePath", GetParentTypeName);
}
private static string GetParentTypeName(IContext context)
{
return context.Request.ParentRequest.Service.FullName;
}
}
so far so good. But When I run the application, Ninject keeps returning NULL for context.Request.ParentRequest. I also tried it with context.Request.Target........ Still it returns NULL for context.Request.Target. What am I doing wrong. Help me out please!!!!