views:

25

answers:

1

Hello,

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"/>
+1  A: 

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.

ho1
Thinking more on things like switches and options of the logger. I will put an example at the main question. Thanks anyway!
SoMoS
@SoMos: 'TraceSource' has a 'Switch' property which you can get and set, I wouldn't be surprised that if you follow the hierarchies up and down those classes and properties you'd find at least some of the things you're looking for.
ho1
@SoMos: Saw something somewhere about My.Log use the DefaultSwitch and the TraceSource on My.Log has a `Switch` property, which has a `Level` property as described here http://msdn.microsoft.com/en-us/library/system.diagnostics.sourceswitch.level.aspx.
ho1