使用企业库4.1多个进程相同的文件记录 [英] Logging from multiple processes to same file using Enterprise Library 4.1

查看:84
本文介绍了使用企业库4.1多个进程相同的文件记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我同时运行,我想记录到同一个文件中的若干进程。

I have several processes running concurrently that I want to log to the same file.

我们一直在使用企业库4.1记录应用程序块(以 RollingFlatFileTraceListener ),它工作正常,除了它前添加一个GUID到日志文件名时,两个进程试图在同一时间(的怪癖写入日志文件的事实 System.Diagnostics.TextWriterTraceListener 我相信)。

We have been using Enterprise Library 4.1 Logging Application Block (with a RollingFlatFileTraceListener), and it works fine, apart from the fact that it prepends a GUID to the log file name when two processes try to write to the log file at the same time (a quirk of System.Diagnostics.TextWriterTraceListener I believe).

我尝试过各种各样的事情,包括调用 Logger.Writer.Dispose()写入日志文件,但它不是理想的做每一个日志条目被写入时阻塞调用之后。

I've tried various things, including calling Logger.Writer.Dispose() after writing to the log file, but it's not ideal to do a blocking call each time a log entry is being written.

EntLib论坛建议使用MSMQ与分销服务,但并不像MSMQ是不是在我的公司允许的选项。

The EntLib forums suggest using MSMQ with a Distributor Service, but that is not an option as MSMQ is not allowed at my company.

是否有另这样我就可以快速,轻松地从多个线程/进程将记录到同一个文件?

Is there another way I can quickly and easily log from multiple threads/processes to the same file?

推荐答案

遗憾地说,但答案是否定的。文件TraceListeners锁定输出文件中,以便只有一个的TraceListener可以登录到一个文件中。

Sorry to say but the answer is no. The File TraceListeners lock the output file so only one TraceListener can log to a file.

您可以尝试未基于文件(如数据库,事件日志)等跟踪侦听器。

You can try other Trace Listeners that are not file based (e.g. Database, Event Log).

另一个选择我能想到的是写你自己的日志服务(进程外),将记录到该文件,并接受LogEntries。然后创建将消息发送到您的服务定制的跟踪侦听器。

Another option I can think of would be to write your own logging service (out of process) that would log to the file and accepts LogEntries. Then create a custom trace listener that sends a message to your service.

这可能不是一个好主意,因为你将有一个位的定制开发的,再加上它可能会影响性能因为它是一个进程外的调用。基本上你是建立自己的简化伪经销商服务。

It might not be a good idea since you would have a bit of custom development plus it could impact performance since it is an out of process call. Basically you are setting up your own simplified-pseudo-distributor-service.

这篇关于使用企业库4.1多个进程相同的文件记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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