본문 바로가기
IT-개발,DB

[개발] Visual C++ 디버깅 Trace log 파일 작성하기

by SB리치퍼슨 2010. 8. 17.

닷넷 프레임워크 클래스 라이브러리에 있는 Trace 클래스를 이용하면 된다.


String^ logFile = "C:\\service_log.txt";
    TextWriterTraceListener^ serviceTraceListener = nullptr;

    // Create a log file for trace output.
    // A new file is created each time.  If a
    // previous log file exists, it is overwritten.
    StreamWriter^ myFile = File::CreateText( logFile );

    // Create a new trace listener that writes to the text file,
    // and add it to the collection of trace listeners.
    serviceTraceListener = gcnew TextWriterTraceListener( myFile );
    Trace::Listeners->Add( serviceTraceListener );
    Trace::AutoFlush = true;
    Trace::WriteLine( DateTime::Now.ToLongTimeString() + " - Service main method starting...", "Main" );

    // Load the service into memory.
    System::ServiceProcess::ServiceBase::Run( gcnew SimpleService );
    Trace::WriteLine( DateTime::Now.ToLongTimeString() + " - Service main method exiting...", "Main" );

    // Remove and close the trace listener for this service.
    Trace::Listeners->Remove( serviceTraceListener );
    serviceTraceListener->Close();
    serviceTraceListener = nullptr;
    myFile->Close();



반응형

댓글