.Net - Describe how to create Trace Listeners and log Trace
output. - June 03, 2009 at 11:00 AM by Shuchi Gauri
Describe how to create Trace Listeners and log Trace output.
[Conditional("TRACE")]
public static void InitializeUnhandledExceptionHandler()
{
AppDomain.CurrentDomain.UnhandledException +=
new UnhandledExceptionEventHandler(CutomExceptionHandler);
}
public static void CustomExceptionHandler(object sender,
UnhandledExceptionEventArgs args)
{
Exception e=(Exception)
args.ExceptionObject;
Trace.WriteLine("Exception:
"+e.Message+"\n"+e.GetType() +
"\nStack Trace:\n"+e.StackTrace);
MessageBox.Show(
"An error has
occurred:"+e.Message+"\nin: "+e.GetType(),
"Fatal",
MessageBoxButtons.OK,
MessageBoxIcon.Stop,
MessageBoxDefaultButton.Button1);
Trace.Close();
Process.GetCurrentProcess().Kill();
}
[Conditional("DEBUG")]
public static void TrapDebug(string str)
{
Debug.WriteLine("Debug error: "+str);
}
Also read
Trace switches allow us to filter, enable/disable the outputs through Trace. We
can configure them through the config file. 3 types of trace switches:........
switches are configured using the .config file.......
Debug.Write: Debug Mode, Release Mode (used while debuging a
project)...............
What is Break mode?, What are the options for stepping through code?, What is a
Breakpoint?, Define Debug and Trace Class, Explain how to configure Trace
switches in the application's .config file, What are Trace
switches?................
What is break mode? What are the options to step through code?, Debug Vs Trace,
Define trace class, Define Listeners collection of Trace and Debug objects,
Define Trace Switches...................
|