sailing

Everything...

输出trace信息

The program below demonstrates output the trace to three different place, it's a very cool feature in .net, very convenient and exactly what we desire of most of the time.
1 eventlog
2 console
3 textfile



using System;

using System.Collections.Generic;

using System.Text;

using System.Diagnostics;

 

namespace CSharpTest

{

    class Program

    {

        static void Main(string[] args)

        {

            // a. Eventlog, need administrator priviledge

            EventLog.WriteEntry("MyTestApp","Something wrong");

 

            // b. Text File listener

            TextWriterTraceListener textListener = new TextWriterTraceListener("log.txt");

            Trace.Listeners.Add(textListener);

            // c. Console listener

            ConsoleTraceListener consoleListener = new ConsoleTraceListener();

            Trace.Listeners.Add(consoleListener);

            Trace.WriteLine("test trace");

            Trace.Flush();

            Trace.Close();

        }

    }

}

 

posted on 2007-03-07 14:39  乌生鱼汤  阅读(198)  评论(0编辑  收藏  举报

导航