如何以编程方式确定VB应用程序日志的位置? [英] How do I programmatically determine the location of the VB application log?

查看:87
本文介绍了如何以编程方式确定VB应用程序日志的位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在翻新旧的vb.net应用程序,以使其符合Vista中的LUA原则.到目前为止,该应用程序使用了多种日志记录机制,但是核心之一涉及到如果文件夹存在,则将日志写入c:\ temp \.我想用更标准的日志记录机制替换当前的日志记录.

I'm retro-fitting an older vb.net application to bring it into compliance with LUA principles in Vista. Up until now, the application has used a hodgepodge of logging mechanisms, but the core one involved writing a log to c:\temp\ if the folder existed. I want to replace this current logging with a more standard logging mechanism.

这是VB,我决定尝试将My.Application.Log与app.config结合使用,并且可以一直使用(尽管我不希望它转储到漫游配置文件中).不幸的是,用户习惯于使用日志中的信息进行故障排除,以及在提交错误时发送日志,并且移动该日志会很好地隐藏它.

This being VB, I decided to try using My.Application.Log in conjunction with app.config, and that works as far as it goes (though I didn't expect it to dump to the roaming profile). Unfortunately, the users are accustomed to troubleshooting with information from the log, as well as sending the log in when they submit a bug, and moving this log hides it pretty well.

我的想法是通过在应用程序的用户界面中添加指向该日志或至少指向包含该日志的文件夹的链接,使日志更易于访问.但是,我不知道如何确定该链接的指向.

My thought is to make the log a little more accessible by adding a link to it, or at least to the folder that contains it, in the app's UI. I don't know how to determine where that link will point, however.

编辑(添加信息):

我的配置文件或多或少是内置默认值:

My configuration file is more or less the built-in default:

<system.diagnostics>
    <sources>
        <source name="Error Log" switchName="DefaultSwitch">
            <listeners>
                <add name="FileLog"/>
            </listeners>
        </source>
    </sources>
    <switches>
        <add name="DefaultSwitch" value="Information" />
    </switches>
    <sharedListeners>
        <add name="FileLog"
             type="Microsoft.VisualBasic.Logging.FileLogTraceListener, Microsoft.VisualBasic, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"
             initializeData="FileLogWriter"/>
    </sharedListeners>
</system.diagnostics>

我想在配置文件中的FileLogTraceListener上设置一些属性. MaxSize,例如(以前有一个max-size行为).不过,我看不到有任何文档可以说明这一点. (

I'd like to set some of the properties on the FileLogTraceListener in the config file. The MaxSize, e.g. (There was a prior max-size behavior). I don't see any documentation that calls this out, though. (There is some community content at the base of the FileLogTraceListener page that suggests I should be able to, so I'll check that. I'd be much more comfortable if I found some official documented support for this, though.)

如果这样做,我应该能够遍历My.Application.Log上的跟踪侦听器集合,并只需链接到第一个FileLogTraceListener的FullLogFileName.

If I do that, I ought to be able to iterate through the trace listener collection on My.Application.Log and just link to the first FileLogTraceListener's FullLogFileName.

推荐答案

我认为这是可配置的.可以在machine.config文件中配置它,或者可以在应用程序配置文件中覆盖它-您将想要这样做,以便对其进行控制并创建指向它的链接.

I believe this is configurable. It may be configured in the machine.config file, or you can override that in your application config file - which you will want to do so you can control it and create a link to it.

您将要在应用程序配置中添加FileLogTraceListener.

You will want to add a FileLogTraceListener to the app.config.

它在system.diagnostics\sharedListeners部分中.您可以在initializeData属性中指定文件名.

It goes in the system.diagnostics\sharedListeners section. You can specify the filename in the initializeData attribute.

来自MSDN的更多文档:

More documentation from MSDN:

  • Working with Application Logs in Visual Basic
  • Walkthrough: Determining Where My.Application.Log Writes Information
  • Walkthrough: Changing Where My.Application.Log Writes Information

这篇关于如何以编程方式确定VB应用程序日志的位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆