依赖关系问题在大型应用程序中实现EventSource进行语义日志记录 [英] Dependency concerns Implementing EventSource for semantic logging in large application

查看:47
本文介绍了依赖关系问题在大型应用程序中实现EventSource进行语义日志记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究一个包含三个Windows服务和几个正常Windows应用程序(.exe)的大型产品.现在,我们要转到ETW和语义日志记录,并使用Microsoft.Diagnostics.Tracing.EventSource.

I'm working on a large product consisting of a three windows services and several normal windows applications (.exe). Now we want to move to ETW and Semantic Logging, and use the Microsoft.Diagnostics.Tracing.EventSource.

我读到某个地方,应用程序的所有逻辑连接部分都应使用相同的事件源.这意味着我们最好为服务提供一个EventSource.但是,如何在不引入产品中几乎所有程序集之间的依赖关系的情况下做到这一点呢?

I read somewhere that all logically connected parts of the application should use the same event source. This means that preferrably we would like to have pretty much a single EventSource for our services. But how can we do this without introducing dependencies among pretty much all the assemblies in the product?

该应用程序当前由大约70个程序集组成.为了能够在EventSource中创建一个例如接受枚举值的对数方法,包含事件源的程序集必须引用定义该枚举的程序集,这意味着该枚举定义需要从该枚举中移出.使用它的程序集,也许是.exe,指向所有程序集引用的内容.

The application currently consists of about 70 assemblies. And to be able to create a log-method in the EventSource that for example accepts an enum-value, the assembly containing the event source has to reference the assembly defining the enum, which means that the enum definition would need to be moved from the assembly using it, an .exe perhaps, to something that is referenced by all assemblies.

在某个仍使用相同ETW EventSource的应用程序中,是否有某种方法可以使多个从EventSource派生的类?在不希望引入一大堆新依赖项来创建日志类的情况下,在这种情况下用ETW实现语义日志记录的好方法是什么?

Is there some way to have several classes derived from EventSource in one application that still use the same ETW EventSource? Or what would be a good way to implement semantic logging with ETW in a scenario such as this, when it is undesirable to introduce a whole bunch of new dependencies to create your log class?

推荐答案

我通常这样做是为了使接口分离,即使它们使用事件源的单个实例也是如此.在我的个人计算机上,所有带有ISingletonDependency的代码都注册为单例.因此,您可以使用非常特定的方法来调用接口,但是它们仍然是相同的EventSource.

I usually do this so that there is segregation of interfaces even though they use a single instance of an event source. In my ioc all code with ISingletonDependency are registered as singleton. So you can call interfaces with very specific methods but they are still the same EventSource.

希望这会有所帮助.

public MyCompanyEventSource: IMyCompanyEventSource, ISingletonDependency{
}
public IMyCompanyEventSource: IComponentLogger1, IComponentLogger2, IComponentLogger3{
}
public Component1{
       public Component1(IComponentLogger logger){
       }
    }

这篇关于依赖关系问题在大型应用程序中实现EventSource进行语义日志记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆