Tracing the Application

Developers can add their own trace calls to the migrated code using the same switches we have added to the PPJ Framework.

One of the switches is dedicated to the application(Sys.TraceApplication), but developers can use all the other switches as well or add their own. To add tracing information to migrated code use the following API:

Sys.TraceError(Sys.TraceApplication, text, args);
Sys.TraceWarning(Sys.TraceApplication, text, args);
Sys.TraceInfo(Sys.TraceApplication, text, args);
Sys.TraceVerbose(Sys.TraceApplication, text, args);
Sys.TraceException(Sys.TraceApplication, exception, level);

When the level assigned to the switch is equal or higher than the level indicated in the trace call, the trace goes through and gets logged. For example, if you add the following code to your application:

Sys.TraceInfo(
    Sys.TraceApplication, 
    "Login failed. User {0} has been locked.", strUserID);

The trace will be logged only if the Application switch has been set to the level Info (3) or higher:

<system.diagnostics>
<switches>
<add name="Application" value="3" />
</switches>
...
</system.diagnostics>

See MSDN for more information on TraceSwitch and TraceLevel: http://msdn.microsoft.com/en-us/library/system.diagnostics.traceswitch.aspx

Last updated