Share via


Complete DTM Logger Sample Using C#

Note  This content applies to the Windows Logo Kit (WLK). For the latest information using the new Windows Hardware Certification Kit (HCK), see Windows HCK User's Guide on the Windows Hardware Dev Center.

The following code sample shows a typical use of the managed logger to log the start of a test case, a message, an error, and the end of a test case.

using System;
using System.IO;
 
//for logger namespace
using Microsoft.Wtt.Log;
 

namespace testApp
{
    class TestCase
    {
        public TestCase(){}
        public bool InitializeTestCase(string initializationFileName)
        {
            // Perform initialization
            return true;
        }
    }
 
    class MainClass
    {
        [STAThread]
        static void Main(string[] args)
        {
            WttLogger Logger = new WttLogger("$LogFile;$Console");
 
            // Start a test case
            Logger.StartTest("Test 1 - Testing Tracing functions");
 
            Logger.Trace(new LevelError(0x3,ErrorType.Win32,"break"));
 
            // Trace machine info
            Logger.TraceMachineInfo();
 
            // Trace a message by using a message string
            Logger.Trace(new LevelMessage("Testing Tracing Messages"));
 
            // Trace a message by using a user object only
            TestCase userObject = new TestCase();

            Logger.Trace(new LevelMessage(userObject));
 
            // Trace a message by using a user object and a message string
            Logger.Trace(new LevelMessage("Testing Tracing Messages with user Objects",userObject));
 
            // Trace a normal error
            Logger.Trace(new LevelError(0x3,ErrorType.Win32, "Testing Tracing Errors"));
 
            try
            {
                // Generate IOException
                File.Open("c:\toot.txt",FileMode.Open,FileAccess.Read,FileShare.Read);
            }
            catch(Exception exp)
            {
                // Trace an exception error
                Logger.Trace(new LevelError(exp));
            }
 
            // End test case
            Logger.EndTest("Test 1 - Testing Tracing functions", 0, null);
        }    
    }
}

See Also

Code Samples for DTM Logger

 

 

Build date: 9/14/2012