Добавьте метку времени для трассировки. WriteLine ()

Поскольку вы проверяете одну переменную на соответствие нескольким условиям, вам следует использовать что-то вроде этого. Здесь будет выполнен блок кода, где условие истинно, а другие блоки будут игнорироваться.

IF (@ParentVar1 Condition1)
Begin
       IF(@Var1 Condition1)
             BEGIN
              /*Your Code Goes here*/
             END

       ELSE IF(@Var1 Condition2)
              BEGIN
                /*Your Code Goes here*/ 
              END 
       ELSE IF(@Var1 Condition2)
              BEGIN
                /*Your Code Goes here*/ 
              END 
       ELSE IF(@Var1 Condition2)
              BEGIN
                /*Your Code Goes here*/ 
              END 
       ELSE      --<--- Default Task if none of the above is true
             BEGIN
               /*Your Code Goes here*/
             END
End
26
задан 14 May 2009 в 13:41
поделиться

4 ответа

Просто напишите свой собственный метод « TraceLine (string msg) » и начните его вызывать:

void TraceLine(string msg, bool OmitDate)
{
    if (!OmitDate)
        msg = DateTime.Now + " " + msg;
    Trace.WriteLine(msg);
}

void TraceLine(string msg) {TraceLine(msg, false);}
2
ответ дан 28 November 2019 в 06:03
поделиться

Via code

You can configure the TraceOutputOptions flags enum.

var listener = new ConsoleTraceListener() { TraceOutputOptions = TraceOptions.Timestamp | TraceOptions.Callstack };
Trace.Listeners.Add(listener);

Trace.TraceInformation("hello world");

This does not work for Write and WriteLine, you have use the TraceXXX methods.

Via app.config

This can also be configured in your App.config with a somewhat equivalent and using TraceSource:

<configuration>
  <system.diagnostics>
    <trace autoflush="true">
      <sources>
        <source name="TraceSourceApp">
          <listeners>
            <add name="myListener" type="System.Diagnostics.ConsoleTraceListener" traceOutputOptions="Timestamp" />
          </listeners>
        </source>
      </sources>
    </trace>
  </system.diagnostics>
</configuration>

And in code you can:

private static TraceSource mySource =   
        new TraceSource("TraceSourceApp");
static void Main(string[] args)
{
  mySource.TraceInformation("hello world");
}
86
ответ дан 28 November 2019 в 06:03
поделиться

Вы можете написать метод-оболочку, который это сделает:

public static void DoTrace(string message)
{
    DoTrace(message,true);
}

public static void DoTrace(string message, bool includeDate)
{
    if (includeDate) {
        Trace.WriteLine(DateTime.Now + ": " + message);
    } else {
        Trace.WriteLine(message);
    }
}
1
ответ дан 28 November 2019 в 06:03
поделиться

Мы используем log4net TraceAppender, где вы можете легко настроить макет или фильтрацию.

0
ответ дан 28 November 2019 в 06:03
поделиться
Другие вопросы по тегам:

Похожие вопросы: