Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

82 lines
2.8 KiB

  1. //---------------------------------------------------------------------------
  2. // File: SimpleExample
  3. //
  4. // An example program to demonstrate the use of WinTraceProvider class for
  5. // software tracing in C#
  6. //
  7. // Author: Baskar Sridharan
  8. // Date: 19 June 2002
  9. //---------------------------------------------------------------------------
  10. using System;
  11. using Microsoft.Win32.Diagnostics;
  12. /// <summary>
  13. /// Summary description for TraceTest.
  14. /// </summary>
  15. ///
  16. class SimpleExample
  17. //SimpleExample
  18. {
  19. //
  20. // This method shows how to use WinTraceProvider.TraceMessage()
  21. //
  22. static void DebugTracingSample()
  23. {
  24. //Create an instance of WinTraceProvider and provide the GUID for the executable
  25. //of which this class will be a part.
  26. TraceProvider MyProvider = new TraceProvider ("SimpleExample App",new Guid("{8C8AC55E-834E-49cb-B993-75B69FBF6D97}"));
  27. string frmtstr = "Hello {0}";
  28. string frmtstr2 = "Arg0 = {0} Arg1 = {1}";
  29. string frmtstr3 = "Arg0 ={0} Arg1 = {1} Arg2 = {2}";
  30. bool bool_v=false;
  31. byte byte_v=(byte)99;
  32. sbyte sbyte_v = (sbyte)-114;
  33. short short_v = (short)-54;
  34. ushort ushort_v = (ushort)5000;
  35. int int_v = -654;
  36. uint uint_v = (uint)12345;
  37. long long_v = (long)-98765;
  38. ulong ulong_v = (ulong)1234567;
  39. string string_v = "MS World!!!!";
  40. char char_v='G';
  41. decimal decimal_v=(decimal)200.876543243213D;
  42. object decimal_obj = decimal_v;
  43. double double_v=(double)3.00;
  44. float float_v=2.00F;
  45. long tel_no=4254944885;
  46. /** TraceMessages for all the types that are currently supported **/
  47. MyProvider.TraceMessage((uint)TraceFlags.Info,frmtstr,bool_v);
  48. MyProvider.TraceMessage((uint)TraceFlags.Info,frmtstr,byte_v);
  49. MyProvider.TraceMessage(1,frmtstr,sbyte_v);
  50. MyProvider.TraceMessage(1,frmtstr,short_v);
  51. MyProvider.TraceMessage(1,frmtstr,ushort_v);
  52. MyProvider.TraceMessage(1,frmtstr,int_v);
  53. MyProvider.TraceMessage(1,frmtstr,uint_v);
  54. MyProvider.TraceMessage(1,frmtstr,long_v);
  55. MyProvider.TraceMessage(1,frmtstr,ulong_v);
  56. MyProvider.TraceMessage(1,frmtstr,float_v);
  57. MyProvider.TraceMessage(1,frmtstr,double_v);
  58. MyProvider.TraceMessage(1,frmtstr,decimal_v);
  59. MyProvider.TraceMessage(1,frmtstr,char_v);
  60. MyProvider.TraceMessage(1,frmtstr,string_v);
  61. MyProvider.TraceMessage(1,frmtstr2,uint_v,byte_v);
  62. MyProvider.TraceMessage(1,frmtstr3,decimal_v,float_v,long_v);
  63. /** Composite formatting **/
  64. MyProvider.TraceMessage(1,"Composite formatting of a long {0: (###)###-####}",tel_no);
  65. MyProvider.TraceMessage(1,"Composite formatting of a string: Hello |{0,30}|",string_v);
  66. MyProvider.TraceMessage(1,frmtstr3,decimal_v,null,string_v);
  67. }
  68. static void Main(string[] args)
  69. {
  70. DebugTracingSample();
  71. return;
  72. }
  73. }