как вы управляете уровнем прослушивателя трассировки в файле конфигурации

Я пытаюсь изучить встроенные функции трассировки. Я не могу понять, как использовать конфигурацию для установки уровня (информация, предупреждение, ошибка), который записывается в мое прослушивание.

У меня есть файл app.config по умолчанию. В своем коде я использую Trace.TraceInformation () и Trace.TraceError.

Все сообщения записываются в мой текстовый файл. Я хочу иметь возможность что-то изменить в app.config, чтобы он записывал информационные сообщения или просто сообщения об ошибках.

Module1.vb

Sub Main(ByVal args() As String)
    Dim index As Integer = 0
    For Each arg As String In args
        Trace.TraceInformation(String.Format("Sub Main(): arg({1}) = {0}", arg, index))
        Trace.Flush()

        If arg.Split("=").Count = 2 Then
            If String.Compare(arg.Split("=")(0), "mode", True) = 0 Then _Mode = arg.Split("=")(1)
        End If

        index += 1
    Next
End Sub

app.config

    <sources>
        <!-- This section defines the logging configuration for My.Application.Log -->
        <source name="DefaultSource">
            <listeners>
                <add name="FileLog"/>
                <!-- Uncomment the below section to write to the Application Event Log -->
                <!--<add name="EventLog"/>-->
            </listeners>
        </source>
    </sources>
    <switches>
        <add name="DefaultSwitch" value="1" />

    </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"/>
        <!-- Uncomment the below section and replace APPLICATION_NAME with the name of your application to write to the Application Event Log -->
        <!--<add name="EventLog" type="System.Diagnostics.EventLogTraceListener" initializeData="HealthSurvey Console"/> -->
    </sharedListeners>

</system.diagnostics>
21
задан MADCookie 13 September 2010 в 22:58
поделиться