登录共享和映射的诊断上下文 [英] Logging Commons and Mapped Diagnostic Context
问题描述
有其他人做了什么来绕过这一事实下议院测井项目(用于.NET和Java)不支持映射或嵌套的诊断上下文就我知道的?
What have others done to get around the fact that the Commons Logging project (for both .NET and Java) do not support Mapped or Nested Diagnostic Contexts as far as I know?
推荐答案
为了完整起见,我结束了写我自己非常简单的通用接口:
For the sake of completeness, I ended up writing my own very simple generic interface:
public interface IDiagnosticContextHandler
{
void Set(string name, string value);
}
然后实施了log4net的特定版本:
then implemented a Log4Net specific version:
public class Log4NetDiagnosticContextHandler : IDiagnosticContextHandler
{
private readonly Assembly assembly;
private readonly Type mdcType;
public Log4NetDiagnosticContextHandler()
{
this.assembly = Assembly.Load("log4net");
this.mdcType = this.assembly.GetType("log4net.MDC", true);
}
public void Set(string name, string value)
{
this.mdcType.InvokeMember("Set", BindingFlags.InvokeMethod, null, null, new object[] { name, value });
}
}
然后我用一个IoC容器(Spring.Net)带来的正确实施。如果一个不同的日志记录框架后来要求它会是写一个不同的实现,接口改变IOC配置的一个简单的事情。
I then used an IoC container (Spring.Net) to bring in the correct implementation. If a different logging framework was later required it'd be a simple matter of writing a different implementation of that interface changing the IoC configuration.
这篇关于登录共享和映射的诊断上下文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!