如何以编程方式修改 My.Log 设置配置
我们在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
可能取决于您希望能够设置的设置,但如果例如用户想要选择写入文件日志的路径,我认为这可能有效:
My.Log
有TraceSource
属性有一个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 theTraceSource
property which has aListeners
collection. If it contains aFileLogTraceListener
you should be able to cast that and then set/get it'sLocation
property.And the
EventLogTraceListener
can set theEventLog
etc.