????? ???? ??????? ?? "Visual C" #

?????? ????????? ?????? ?????????
???? ???????: 815788 - ??? ???????? ???? ????? ????? ??? ???????.
?????? ??? ????? Microsoft Visual Basic .NET ?? ??? ???????? ???? 313417 .
????? ???? | ?? ????

?? ??? ??????

??????

???? ??? ??????? ????? ??????? ????? ???? ????. ????? ??? ?????? ?? Microsoft .NET Framework. ????? ??????? ??? ?????? ?????? ??????? ??? ???? ??????? ??? ????? ????? ??????? ?? ??? ??? ???????. ??? ?????? ?? ??? ???? ??? ?? ??????? ???? ???????? ?? .NET Framework.

???????

???? ??????? ??????? ??????? ?????? ??? ????? ?????? ???????? ?????? ? ??? ??????? ???? ???????:
  • ???? ??????? Microsoft Windows 2000 ?? Microsoft Windows XP ?? Microsoft Windows Server 2003
  • Microsoft Visual C#
????? ??? ??????? ????? ??? ??????? ??? ????? ????????.

??? ?? ?????


???? ??????? ???????? ?? ?????? Create a Sample with the Debug Class ????? ????? ????? ???? ???? ?????? ??? Debug ?????? ??????? ??? ????? ????????.

??? ????? ???????? ????? ??????? ?????? ????? Debug ?????? ??????? ???? ?????? ?? ?????? ????? ????? ?????? ????? ?? ???? ??? ?? ?????? ??????? ???? ??????. ???? ???????? ???? ??????? ???? ???? ??? Debug ?? ???? ????? Visual Studio ???? ??????? ????????? (IDE).

?????? ????? ???????? ???????? ????? WriteLine ?????? ????? ??????? ??? ????? ???. ??? ??????? ??? ??????? ?????? ????? ???? ?? ????? ??? ??? ????? ?? ???? ???????.

??? ??????? ??????? ????? ????? Debug ?????? ????? ???? ????? ??? ??? ?? ????? ??? ???? ??? false. ???? ??????? ?? ???? ???? ????? ??? ????????. ????? ???? ?????? ??????? ??? ??????? ???? ????? Debug.Assert. ????? ???? ?????? ????? ????? ??????? ??????? ???????:
  • ?????:???? ??????? ??? ???????.
  • ????? ??????:???? ??????? ??? ???????.
  • ?????:????? ????? ???????.
???????? ???? ????? ??? ??? ??? ??????? ??? ?????? ???????.

????? ????? ????? ??????? ?? ??? Debug ??? ????? ???? ?? ?????? ?????. ????? ??? Debug ?????? ???? Listeners ???? ????? ?????? ????.

????? ????? ??????? ?? ???? ???? ?? ????? ??????? ??? ??? ????.

????? ?? ???? ????? ?? ?????? ????? ?? ????? ???? ??? Debug. ?????? ????? TextWriterTraceListener ?????? ???????? ????. ????? ????? ????? ???? TextWriterTraceListener ???? ??????? ????? ??.

????? ??? ????? ??????? ???????? ?? ???:
  • ???? ???? ?????? ???????? ??????? System.Console.Out.
  • ??? ??? (.txt) ???????? ????? System.IO.File.CreateText("FileName.txt").
??? ????? ???? TextWriterTraceListener ??? ????? ?????? ??? ?????? Debug.Listeners ????? ??????? Debug.

????? ????? ???????? ??? Debug

  1. ??? ????? Visual Studio ?? Visual C# Express.
  2. ????? ????? ??????? Visual C# ?? ???? ?????? ???? ???? conInfo. ??? ????? Class1 ?? Visual Studio .NET. ??? ????? Program.cs ?? Visual Studio 2005.
  3. ????? ????? ????? ?????? ?????? ?? Class1 ?? Program.cs.
    using System.Diagnostics;
  4. ?????? ????????? ????? ??? ??????? ??? ???? ????? ?????? ????? ??????? ??? ??????? ???????:
    string sProdName = "Widget";
    int iUnitQty = 100;
    double dUnitCost = 1.03;
  5. ??? ??????? ???? ???? ????? ??? ????? ??????? ????? ????? WriteLine. ???? ?????? ???????? CTRL + ALT + O ???? ?? ???? ?????? ?????.
    Debug.WriteLine("Debug Information-Product Starting ");
  6. ?????? ??? ?????? ??????? ? ?????? ??????? ????? ????? ???? ????? ????? ??????? ??????? ?? ???? ???????:
    Debug.Indent();
  7. ???? ????? ????????? ??????? ?????? ????? WriteLine ??? ???:
    Debug.WriteLine("The product name is " + sProdName);
    Debug.WriteLine("The available units on hand are" + iUnitQty.ToString());
    Debug.WriteLine("The per unit cost is " + dUnitCost.ToString());
  8. ????? ????? ??????? ??????? WriteLine ???? ????? ????? ???? ????? ????? ????????. ??? ???? ??????? ???? ????????? ???????? ??????? ????? System.Xml.XmlDocument ?? ???? ???????:
    System.Xml.XmlDocument oxml = new System.Xml.XmlDocument();
    Debug.WriteLine(oxml);
  9. ???? ?? ????? ????? ????? ???????? ??????? ?????? ?? ????? WriteLine ?????? ???????. ??? ???? ??? ??????? ??????? ???? ??????? "?????: ?????." ??? ???? ??????? ???? ????? ????? ?? ????????? ???????? ??????? "???: ??? ?????? ?? ???? ????? ????????" ?? ????? ????:
    Debug.WriteLine("The product name is " + sProdName,"Field");
    Debug.WriteLine("The units on hand are" + iUnitQty,"Field");
    Debug.WriteLine("The per unit cost is" + dUnitCost.ToString(),"Field");
    Debug.WriteLine("Total Cost is  " + (iUnitQty * dUnitCost),"Calc");
  10. ???? ??? ???? ??????? ??????? ??? ??? ?? ????? ??? ????? ??? true ?????? ??????? ??????? WriteLineIf ??? Debug. ??? ????? ???? ?????? ????? ??????? ????? ????? WriteLineIf. ??????? ??????? WriteLineIf ?? ??????? ???? ???? ??? ??? ?? ????? ????? ?? ??????? ?????? ??? true.
    Debug.WriteLineIf(iUnitQty > 50, "This message WILL appear");
    Debug.WriteLineIf(iUnitQty < 50, "This message will NOT appear");
    
  11. ??????? ????? ????? ??? Debug ???? ???? ?????? ????? ??????? ??? ??? ?? ????? ??? ???? ??? false:
    Debug.Assert(dUnitCost > 1, "Message will NOT appear");
    Debug.Assert(dUnitCost < 1, "Message will appear since dUnitcost < 1 is false");
    
  12. ????? ?????? TextWriterTraceListener ?????? ??? ???? ???? ?????? (tr1) ???????? ??? ??? ??? ???? Output.txt (tr2) ?? ?? ?????? ?? ???? ??? ?????? Listeners Debug:
    TextWriterTraceListener tr1 = new TextWriterTraceListener(System.Console.Out);
    Debug.Listeners.Add(tr1);
            
    TextWriterTraceListener tr2 = new TextWriterTraceListener(System.IO.File.CreateText("Output.txt"));
    Debug.Listeners.Add(tr2);
  13. ? ????? ??????? ????? Unindent ????? ??????? ??????? ??????? ??????? ???? ???? ??? Debug. ??? ??????? ????? ????? ? ???????? Unindent ????, ???? ?????? ???? ??????? ?? ????????.
    Debug.Unindent();
    Debug.WriteLine("Debug Information-Product Ending");
  14. ?????? ?? ?? ?? ???? ???? ????? ??????? ????? ?? ??????? ??????? ??? ??????? ??????? ??? Debug:
    Debug.Flush();

???????? ??? ????

????? ????? ??????? ??? ???? ?????? ????? ?? ????? ????? ??? ?????????. ?????? ???? ???? ????????? Debug ???? ???????? ??? ?????? ??????? ??? ?? ??? ??????:
  • WriteLine
  • WriteLineIf
  • ????? ?????
  • unindent
  • ?????
  • ???
????? ??????? ???? ????? Debug ???? ????? ?? ???? ?? ??? ???????. ?? ????? Debug ????? ???? ?? ?? "????" ? "????? ??????? ????. ???? ??????? ??????? ?? ?? ?? ??? ?????? ??? ???? ???????? ????. ??? ???? ???? ????? "????? ???? ???????" ??? ??????? ?? ??? ????. ?????? Project "????? ???? ?????" ?? invocations Debug ????? ???.
Trace.WriteLine("Trace Information-Product Starting ");
Trace.Indent();

Trace.WriteLine("The product name is "+sProdName);
Trace.WriteLine("The product name is"+sProdName,"Field" );
Trace.WriteLineIf(iUnitQty > 50, "This message WILL appear");
Trace.Assert(dUnitCost > 1, "Message will NOT appear");
        
Trace.Unindent();
Trace.WriteLine("Trace Information-Product Ending");

Trace.Flush();

Console.ReadLine();

???? ?? ???? ?? ???

  1. ???? ?? ?? ????? ??????? ???? ??????.
  2. ?? ???? ??? ???? ???? ?????? ?????? ???? ?????? ???????? CTRL + ALT + L ???? ??? ??????.
  3. ???? ??? ?????? ?????? ??? conInfo ??? ?? ???? ??? ?????.
  4. ?? ????? ?????? ?? ???? ??????? conInfo ??? ?????? ????? ???? ?? ?? ???? ????? ??? ?????.

    ?????? ?? Visual C# 2005 ?? Visual C# 2005 Express Edition ? ???? ??? ????? ?? ???? conInfo.
  5. ???? ?????? ????? ?? ????? ????? ???? ??????? ???????? ???? ??? ?????? (?????) ?? ????? ? ?? ???? ??? ?????. ?? Visual C# 2005 ??? Visual C# 2005 Express Edition ???? ??? ??? (?????) ?? "?????" ?? ???? ??????? ???????? ????? ?? ???? Debug ?? ???? ??? ??? ?? ??????? ???.
  6. ???? CTRL + ALT + O ???? ?????? ?????.
  7. ???? ??????? F5 ?????? ????????? ????????. ??? ???? ???? ?????? ??? ??????? ???? ??? "?????".
  8. ?? ???? ???? ??????, ???? ENTER. ??? ????? ???????? ? ??? ?? ???? ?????? ????? ??????? ??????? ??? ???
        Debug Information-Product Starting 
        The product name is Widget
        The available units on hand are100
        The per unit cost is 1.03
        System.Xml.XmlDocument
        Field: The product name is Widget
        Field: The units on hand are100
        Field: The per unit cost is1.03
        Calc: Total Cost is  103
        This message WILL appear
        ---- DEBUG ASSERTION FAILED ----
    ---- Assert Short Message ----
    Message will appear since dUnitcost  < 1 is false
    ---- Assert Long Message ----
    
    
        at Class1.Main(String[] args)  <%Path%>\class1.cs(34)
    
        The product name is Widget
        The available units on hand are100
        The per unit cost is 1.03
    Debug Information-Product Ending
    Trace Information-Product Starting 
        The product name is Widget
        Field: The product name isWidget
        This message WILL appear
    Trace Information-Product Ending
                        
    
  9. ???? ???? ?????? ???? Output.txt ??? ??? ??????? ??????:
    The product name is Widget
        The available units on hand are 100
        The per unit cost is 1.03
    Debug Information-Product Ending
    Trace Information-Product Starting 
        The product name is Widget
        Field: The product name is Widget
        This message WILL appear
    Trace Information-Product Ending			
    
?????? ??? ??? ????? Output.txt ?? ??? ?????? ?? conInfo ?????? ??????? (conInfo.exe). ????? ?? ???? ??? ?? ?????? \bin ??? ??? ????? ???? ?????. ???? ???????? ???? C:\Documents and Settings\ User login \My Documents\Visual Projects\conInfo\bin Studio. ?? Visual C# 2005 ??? Visual C# 2005 Express Edition ???? ??? Output.txt ?? ?????? ??????:
\My Documents\Visual 2005\Projects\conInfo\conInfo\bin\Debug Studio C:\Documents and Settings\ User login


????? ??? ?????

   using System;
   using System.Diagnostics;

   class Class1
   {
      [STAThread]
      static void Main(string[] args)
      {
         string sProdName = "Widget";
         int iUnitQty = 100;
         double  dUnitCost = 1.03;
         Debug.WriteLine("Debug Information-Product Starting ");
         Debug.Indent();
         Debug.WriteLine("The product name is "+sProdName);
         Debug.WriteLine("The available units on hand are"+iUnitQty.ToString());
         Debug.WriteLine("The per unit cost is "+ dUnitCost.ToString());

         System.Xml.XmlDocument oxml = new System.Xml.XmlDocument();
         Debug.WriteLine(oxml);

         Debug.WriteLine("The product name is "+sProdName,"Field");
         Debug.WriteLine("The units on hand are"+iUnitQty,"Field");
         Debug.WriteLine("The per unit cost is"+dUnitCost.ToString(),"Field");
         Debug.WriteLine("Total Cost is  "+(iUnitQty * dUnitCost),"Calc");

         Debug.WriteLineIf(iUnitQty > 50, "This message WILL appear");
         Debug.WriteLineIf(iUnitQty < 50, "This message will NOT appear");

         Debug.Assert(dUnitCost > 1, "Message will NOT appear");
         Debug.Assert(dUnitCost < 1, "Message will appear since dUnitcost  < 1 is false");

         TextWriterTraceListener tr1 = new TextWriterTraceListener(System.Console.Out);
         Debug.Listeners.Add(tr1);
        
         TextWriterTraceListener tr2 = new TextWriterTraceListener(System.IO.File.CreateText("Output.txt"));
         Debug.Listeners.Add(tr2);
         
 
         Debug.WriteLine("The product name is "+sProdName);
         Debug.WriteLine("The available units on hand are"+iUnitQty);
         Debug.WriteLine("The per unit cost is "+dUnitCost);
         Debug.Unindent();
         Debug.WriteLine("Debug Information-Product Ending");
         Debug.Flush();
         
         Trace.WriteLine("Trace Information-Product Starting ");
         Trace.Indent();

         Trace.WriteLine("The product name is "+sProdName);
         Trace.WriteLine("The product name is"+sProdName,"Field" );
         Trace.WriteLineIf(iUnitQty > 50, "This message WILL appear");
         Trace.Assert(dUnitCost > 1, "Message will NOT appear");
        

         Trace.Unindent();
         Trace.WriteLine("Trace Information-Product Ending");

         Trace.Flush();

         Console.ReadLine();
      }			
   }


??????? ????? ????????

  • ??? ??? ??? ??????? ???? ?? ??????? ? ??? ????? ??????? ??? Debug.
  • ??? ????? ??? TextWriterTraceListener ??? ???? TextWriterTraceListener ????? ????? ?? ???? ????? Debug. ???? ??? ??? ????? ?? ?? ??? ??? ??????? ??????? Add???? ?? ????? Debug ?????? TextWriterTraceListener ??? ??? Listeners.
  • ??? ??? ?????? ???? Listeners ??? ??? ?? ???? ????? Debug ?? ????? ?? ??? ??????? ??? ????? ?? ?? ??? ??? ????? ?? ???? ?????? ???????.
             TextWriterTraceListener myWriter = new TextWriterTraceListener(System.Console.Out);
             Debug.Listeners.Add(myWriter);
            
             TextWriterTraceListener myCreator = new TextWriterTraceListener(System.Console.Out);
             Trace.Listeners.Add(myCreator);
             
    

?????

????? ?? ?????????? ???? ???????? ??????? ?? .NET Framework ????? ?????? ???????:
???? ???
http://msdn2.microsoft.com/en-us/library/system.diagnostics.trace(vs.71).aspx

????? ????? ???
http://msdn2.microsoft.com/en-us/library/system.diagnostics.debug(vs.71).aspx

???????

???? ???????: 815788 - ????? ??? ??????: 05/???? ?????/1429 - ??????: 4.3
????? ???
  • Microsoft Visual C# 2008 Express Edition
  • Microsoft Visual C# 2005 Express Edition
  • Microsoft Visual C# 2005
  • Microsoft Visual C# .NET 2003 Standard Edition
  • Microsoft Visual C# .NET 2002 Standard Edition
????? ??????: 
kbmt kbprogramming kbdebug kbnamespace kbhowtomaster KB815788 KbMtar
????? ????
???: ??? ????? ??? ?????? ???????? ?????? ????? ???? ????? ?????????? ????? ?? ????????? ?????? ????. ???? ???? ?????????? ???? ?? ???????? ???????? ?????? ????????? ????? ????????? ???????? ????? ???????? ?????? ?? ?????? ??? ?? ???????? ???????? ?? ????? ??????? ?????? ??? ??????? ?????? ??. ?????? ?? ???? ??? ??????? ???????? ????? ?? ???? ????? ?????? ??? ????? ??? ????? ??????? ?? ????? ?? ?????? ??? ??? ??????? ??????? ?? ????? ????? ????? ????? ?????. ?? ????? ???? ?????????? ??????? ??? ????? ?? ??????? ?? ????? ?????? ?? ??? ????? ?? ????? ??????? ?? ???????? ?? ??? ???????. ???? ???? ?????????? ???????? ??? ????? ?????? ??????? ??????
???? ??? ????? ??????? ?????? ??????????815788

????? ???????

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com