如何以编程方式修改 My.Log 设置配置

发布于 2024-09-06 10:49:08 字数 802 浏览 2 评论 0原文

我们在 Vb.Net 中有几个应用程序使用内置日志系统(My.Log)来写入日志信息。到目前为止,该系统是在执行之前由 application.config 文件配置的,但现在我们想让用户选择一些选项。

有没有一种方法不需要解析XML文件并对其进行处理?是否有像 My.Settings 这样的可用工具可以完成肮脏的工作?

提前致谢。

一个示例是能够将 DefaultSwitch 值从 Verbose 修改为 Warning 或更改 FileLog 的属性(如 maxFiles 属性):

<switches>
    <add name="DefaultSwitch" value="Verbose" />
</switches>
<sharedListeners>
<add name="FileLog" type="Sipro.Utils.ExtendedLogTraceListener, Sipro.Utils, Version=1.0.6.0, Culture=neutral, PublicKeyToken=null"
    autoflush="True"
    delimiter=" - "
    diskspaceexhaustedbehavior="DiscardMessages"
    includehostname="False"
    logfilecreationschedule="Daily"
    maxfiles="31"
    fullinformation="True"
    includeDate="True"
    includeTicks="True"/>

we have several applications in Vb.Net using the built in log system (My.Log) to write log information. Until now this system was configured by the application.config file before execution but now we want to let the user to choose some options.

Is there a way that does not requires to parse the XML file and process it? Is there available something like My.Settings that will do the dirty job done?

Thanks in advance.

An example would be to be able to modify the DefaultSwitch value from Verbose to Warning or changing a property of the FileLog like the maxFiles attribute:

<switches>
    <add name="DefaultSwitch" value="Verbose" />
</switches>
<sharedListeners>
<add name="FileLog" type="Sipro.Utils.ExtendedLogTraceListener, Sipro.Utils, Version=1.0.6.0, Culture=neutral, PublicKeyToken=null"
    autoflush="True"
    delimiter=" - "
    diskspaceexhaustedbehavior="DiscardMessages"
    includehostname="False"
    logfilecreationschedule="Daily"
    maxfiles="31"
    fullinformation="True"
    includeDate="True"
    includeTicks="True"/>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

远昼 2024-09-13 10:49:08

可能取决于您希望能够设置的设置,但如果例如用户想要选择写入文件日志的路径,我认为这可能有效:

My.LogTraceSource 属性有一个 Listeners 集合。如果它包含 FileLogTraceListener,您应该能够对其进行强制转换,然后设置/获取它的 Location 属性。

EventLogTraceListener可以设置EventLog等。

Might depend on what settings you want to be able to set but if for example the user wants to select the path to where a file log is written I think this might work:

My.Log has the TraceSource property which has a Listeners collection. If it contains a FileLogTraceListener you should be able to cast that and then set/get it's Location property.

And the EventLogTraceListener can set the EventLog etc.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文