多个客户端使用Logging Application Block写入单个文件

时间:2022-11-26 21:58:57

I have the following scenario: 1. .NET UI side uses Logging App Block to write to a flat file 2. Unmanaged Windows Service uses a proprietary logger to write to the same file as 1.

我有以下场景:1。.NET UI端使用Logging App Block写入平面文件2.非托管Windows Service使用专有记录器将同一文件写入1。

Question: Is there a way to enable FlatFile TraceListener to close it's file handle once the entry is logged so that the Windows Service could also write to the file?

问题:有没有办法在记录条目后启用FlatFile TraceListener关闭它的文件句柄,以便Windows服务也可以写入文件?

Thanks!

Update: I included Microsoft.Practices.EnterpriseLibrary.Logging.Logger.Writer.Dispose(); and this closes the stream, so this would do the trick -- just curious if there is another way to do this.

更新:我包括Microsoft.Practices.EnterpriseLibrary.Logging.Logger.Writer.Dispose();这会关闭流,所以这样就可以了 - 只是好奇,如果有另一种方法可以做到这一点。

Update2: Final Notes

Update2:最终笔记

P&P proposes to write to a single MSMQ from multiple applications. This way you won't need to call Dispose(), etc.

P&P建议从多个应用程序写入单个MSMQ。这样你就不需要调用Dispose()等。

3 个解决方案

#1


2  

I've had to deal with this using log4net. I wasn't able to make use of the logging framework's file logging support at all, and had to roll my own log appender that catches sharing violations. At that point, your choices are either to buffer events in memory and write them out later or to block until you can get access to the file.

我必须使用log4net处理这个问题。我根本无法使用日志记录框架的文件日志记录支持,并且必须滚动我自己的日志附加程序来捕获共享冲突。此时,您可以选择缓冲内存中的事件并稍后将其写出或阻止,直到您可以访问该文件。

#2


0  

I think that your choice is the best way to take care of it - just dispose the writer after you're done, which should finalize and release all of the resources that the writer still holds.

我认为您的选择是处理它的最佳方式 - 只需在完成后处理作者,这应该最终确定并释放作者仍然拥有的所有资源。

Also, I'd be worried about both processing trying to write at the same time and it causing an exception, but perhaps the App Block has some workaround code for that built in.

此外,我担心同时处理尝试写入并导致异常,但也许App Block有一些内置的解决方法代码。

#3


0  

Where do you get the .Dispose from? I type in EnterpriseLibrary.Logging.Logger.Writer but the .Writer as no methods or properties, no .Dispose.

你从哪里得到.Dispose来自?我键入EnterpriseLibrary.Logging.Logger.Writer,但.Writer没有方法或属性,没有.Dispose。

Thanks,

TCW

Found it :

找到了 :

Import Microsoft.Practices.EntLib.Common does the trick.

导入Microsoft.Practices.EntLib.Common可以解决问题。

#1


2  

I've had to deal with this using log4net. I wasn't able to make use of the logging framework's file logging support at all, and had to roll my own log appender that catches sharing violations. At that point, your choices are either to buffer events in memory and write them out later or to block until you can get access to the file.

我必须使用log4net处理这个问题。我根本无法使用日志记录框架的文件日志记录支持,并且必须滚动我自己的日志附加程序来捕获共享冲突。此时,您可以选择缓冲内存中的事件并稍后将其写出或阻止,直到您可以访问该文件。

#2


0  

I think that your choice is the best way to take care of it - just dispose the writer after you're done, which should finalize and release all of the resources that the writer still holds.

我认为您的选择是处理它的最佳方式 - 只需在完成后处理作者,这应该最终确定并释放作者仍然拥有的所有资源。

Also, I'd be worried about both processing trying to write at the same time and it causing an exception, but perhaps the App Block has some workaround code for that built in.

此外,我担心同时处理尝试写入并导致异常,但也许App Block有一些内置的解决方法代码。

#3


0  

Where do you get the .Dispose from? I type in EnterpriseLibrary.Logging.Logger.Writer but the .Writer as no methods or properties, no .Dispose.

你从哪里得到.Dispose来自?我键入EnterpriseLibrary.Logging.Logger.Writer,但.Writer没有方法或属性,没有.Dispose。

Thanks,

TCW

Found it :

找到了 :

Import Microsoft.Practices.EntLib.Common does the trick.

导入Microsoft.Practices.EntLib.Common可以解决问题。