是否有可能设置的TraceSwitch编程方式模拟的app.config项?有可能、方式、config、TraceSwitch

2023-09-06 08:17:33 作者:◆永灬恒丨国度

我使用的是第三方的工具,它在内部增加使用以下code跟踪消息:

I am using a third party tool which internally adds trace messages using the following code:

System.Diagnostics.Trace.WriteLineIf(
    new System.Diagnostics.TraceSwitch("Switch", "").TraceInfo, message);

在这种情况下,看来我必须将开关添加到我的app.config文件,以获得跟踪消息出现:

In this scenario, it appears that I must add the switch to my app.config file to get the trace messages to appear:

<system.diagnostics>
  <switches>
    <add name="Switch" value="3" />
  </switches>
</system.diagnostics>

因为不是所有的我的用户授予管理员权限进行更改在Program Files目录下这将成为一个问题。

Since not all of my users are granted administrator rights to make changes in the Program Files directory this becomes an issue.

是否有可能以编程方式设置的TraceSwitch并允许第三方工具来写的跟踪消息?

Is it possible to set the TraceSwitch programmatically and allow the third party tool to write the trace messages?

推荐答案

是对问题的第一部分。恐怕没有第二部分,因为第三方正在对每次调用WriteLineIf新TraceSwtich。在我看来,这似乎第三方控件有一个失败的实现,因为1)它应该让你改变开关编程通过属性,方法或函数,2)它是阅读每一丝的配置文件声明。

Yes to first part of question. Probably no to second part, since the third-party is creating a new TraceSwtich on each call to WriteLineIf. In my opinion, it seems the third-party control has a failed implementation because 1) it should allow you to change the "switch" programmatically through a property, method, or function, and 2) it is reading the config file on every trace statement.