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 Microsoft's TraceSwitch reference for the underlying level checks.
What to Record
Log the operation, outcome, elapsed time where useful, and a non-sensitive correlation identifier. Preserve exception context. Avoid building large messages or serializing objects before checking whether a detailed trace is enabled; function arguments are evaluated even when the callee suppresses output.
For web applications, include a safe request or session correlation value so concurrent users' operations can be distinguished. Do not use passwords, tokens, or entire connection strings as identifiers.