简体   繁体   English

具有共享web.config日志记录的多个Web服务,以使用Ent Lib分离平面文件

[英]Multiple Webservices with shared web.config logging to separate flat files with Ent Lib

I'm working on a project where I'm required to use Enterprise Library v.3.1.1.0 Logging block (wish it was log4net or nlog, but I don't get a choice). 我正在一个需要使用Enterprise Library v.3.1.1.0日志记录块的项目(希望它是log4net或nlog,但我没有选择)。 We have an IIS application where several WCF webservices are hosted, and they share a single web.config file. 我们有一个IIS应用程序,其中托管了多个WCF Web服务,它们共享一个web.config文件。 This is also something I'm not at liberty to change. 这也是我无权改变的事情。

None of these services had any logging implemented previously. 这些服务以前都没有实现任何日志记录。

So it's pretty straight forward to use the Ent Lib Config utility to set up a rolling flat file listener, and log to a text file the way I want. 因此,使用Ent Lib Config实用程序来设置滚动平面文件侦听器并按照我想要的方式登录到文本文件是非常简单的。 The problem I'm having is configuring it properly though so each service can have their own separate log file, while they still all share the same web.config. 我遇到的问题是如何正确配置它,以便每个服务可以有各自独立的日志文件,而它们仍共享相同的web.config。

I've gone through several tutorials, but I'm not understanding how to do this. 我已经看过一些教程,但是我不了解如何做到这一点。

Any tips? 有小费吗?

The configuration in the web.config is static so there will be one file per configured trace listener. web.config中的配置是静态的,因此每个配置的跟踪侦听器将只有一个文件。 One approach to achieve one file per service is to have each service log to a different category and each category uses a different trace listener. 为每个服务获取一个文件的一种方法是使每个服务日志都属于不同的类别,并且每个类别都使用不同的跟踪侦听器。 This could even be done programmatically so that services can add their own trace listener's at runtime although this is a bit more advanced than updating the configuration file manually (eg ensure service is added only once as well as ensuring that when the configuration is updated it is thread-safe). 这甚至可以通过编程方式完成,以便服务可以在运行时添加其自己的跟踪侦听器,尽管这比手动更新配置文件要先进一些(例如,确保仅添加一次服务以及确保在更新配置时添加服务)线程安全的)。

Enterprise Library does not have anything analogous to log4net's hierarchical loggers so there is no out of the box way to use reflection to route log messages based on the originating class. Enterprise Library没有类似于log4net的分层记录器的任何内容,因此没有开箱即用的方式使用反射来基于原始类路由日志消息。 It might be possible but you will have to write some code. 可能有可能,但是您将不得不编写一些代码。 You could write a Logger facade class to set the category based on the callers namespace. 您可以编写Logger门面类,以根据调用者名称空间设置类别。 (Also note that there is no namespace wildcard matching like log4net.) (还请注意,没有像log4net这样的名称空间通配符匹配。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM