tags:

views:

636

answers:

4

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.

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.

Edit (Add'l info):

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>

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.)

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.

A: 

One possibility might be to skip the My.Application.Log altogether and go straight to the System.Diagnostics.TraceListeners. I can choose my own log folder that way, and I'll definitely know where it's located.

Greg D
I'd prefer to stick with the more VB-y solution in VB, if it's at all possible.
Greg D
+1  A: 

The solution is to use the Microsoft.VisualBasic.Logging.FileLogTraceListener. This trace listener supports retrieval of the full log path via its FullLogFileName property as well as customization of the location via the Location property.

Greg D
+1  A: 

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.

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

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

More documentation from MSDN:

Sam Meldrum
A: 

I'm a fan of using the built-in Trace object for logging. Additionally, if you need to preserve the old behavior of using a temp file look at System.IO.Path.GetTempFileName().

Joel Coehoorn