TextWriterTraceListener 和带有 GUID 的跟踪文件名
我在应用程序中使用 TextWriterTraceListener (System.Diagnostics) 来跟踪异常等一些事情,...
应用程序在终端服务器上运行,如果有许多用户使用同时,侦听器开始创建许多文件名中带有随机 GUID 的跟踪文件。
是否有可能或解决方法来避免这种行为?
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 ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我刚刚查看了 TextWriterTraceListener 页面下方 1/3 处有一条注释
因此,这似乎是设计使然。如果该文件确实不可用,那么当前的实现对此无能为力。您可以尝试编写 TextWriterTraceListener 的自定义实现,该实现重写相关的 Write/WriteLine 方法,以便将输出发送到每个用户的文件,并使用更适合您需求的名称。
如果您想要终端服务器上所有用户的所有日志记录都转到单个文件,那么您几乎肯定需要运行某种“第三方”进程来“拥有”该文件并同步写入它,例如由您的自定义 TextWriterTraceListener 调用的 Windows 服务
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
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
修复是否意外多次调用 Trace.Listeners.Add(xxx Listener)?
因为如果您添加了多个侦听器,那么当您调用 Trace.writeline(); 时,它们也会写入所有侦听器;
此外,当您关闭应用程序时,本地 IIS 可能会继续使用该文件。
Was the fix calling the Trace.Listeners.Add(xxx listener) multiple times on accident?
Because if you have multiple listeners added they write too all listeners when you call the Trace.writeline();
Also local IIS might be continueing to have the file in use when you shut down the application.
我目前正在测试在输出方法中添加 System.Diagnostics.Trace.Listeners.Clear()...
I am currently testing the addition of System.Diagnostics.Trace.Listeners.Clear() in my output method...