TextWriterTraceListener and trace filenames with GUIDs

本秂侑毒 提交于 2019-12-19 12:28:10

问题


I use TextWriterTraceListener (System.Diagnostics) in my application to trace several things like exceptions,...

The application is running on a terminal server and if there are many users using it simultaneously the listener starts to create many tracefiles with random GUIDs in the filename.

Are there possibilities or workarounds to avoid this behaviour ?


回答1:


I've just taken a look at the documentation for TextWriterTraceListener and there's a note about 1/3 of the way down the page

If an attempt is made to write to a file that is in use or unavailable, the file name is automatically prefixed by a GUID

So, this would appear to be by design. If the file is indeed unavailable then there's nothing that can be done about it with the current implementation. What you could try doing is writing a custom implementation of TextWriterTraceListener that overrides the relevant Write/WriteLine methods so that the output goes to a file, per user, with a name that better suits your needs.

If what you want is for ALL logging from ALL users on the Terminal Server to go to a single file, then you'll almost certainly need to have some kind of "3rd party" process running that "owns" the file and synchronises writes to it, such as a Windows Service that is then called by your custom TextWriterTraceListener



来源:https://stackoverflow.com/questions/2341110/textwritertracelistener-and-trace-filenames-with-guids

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!