Debug Sınıf

Tanım

Kodunuzun hatalarını ayıklamanıza yardımcı olan bir Yöntemler ve özellikler kümesi sağlar.Provides a set of methods and properties that help debug your code.

public ref class Debug abstract sealed
public ref class Debug sealed
public static class Debug
public sealed class Debug
type Debug = class
Public Class Debug
Public NotInheritable Class Debug
Devralma
Debug

Örnekler

Aşağıdaki örnek, Debug bir program yürütmenin başlangıcını ve sonunu göstermek için kullanır.The following example uses Debug to indicate the beginning and end of a program's execution. Örnek ayrıca Indent Unindent izleme çıkışını ayırt etmek için ve kullanır.The example also uses Indent and Unindent to distinguish the tracing output.

// Specify /DDEBUG when compiling.

#using <System.dll>
using namespace System;
using namespace System::Diagnostics;

int main( void )
{
   #if defined(DEBUG)
   Debug::Listeners->Add( gcnew TextWriterTraceListener( Console::Out ) );
   Debug::AutoFlush = true;
   Debug::Indent();
   Debug::WriteLine( "Entering Main" );
   #endif
   Console::WriteLine( "Hello World." );
   #if defined(DEBUG)
   Debug::WriteLine( "Exiting Main" );
   Debug::Unindent();
   #endif
   return 0;
}
// Specify /d:DEBUG when compiling.

using System;
using System.Data;
using System.Diagnostics;

class Test
{
    static void Main()
    {
       Debug.Listeners.Add(new TextWriterTraceListener(Console.Out));
       Debug.AutoFlush = true;
       Debug.Indent();
       Debug.WriteLine("Entering Main");
       Console.WriteLine("Hello World.");
       Debug.WriteLine("Exiting Main");
       Debug.Unindent();
    }
}
' Specify /d:DEBUG=True when compiling.

Imports System.Data
Imports System.Diagnostics

Class Test

    Shared Sub Main()
    
        Debug.Listeners.Add(New TextWriterTraceListener(Console.Out))
        Debug.AutoFlush = True
        Debug.Indent()
        Debug.WriteLine("Entering Main")
        Console.WriteLine("Hello World.")
        Debug.WriteLine("Exiting Main")
        Debug.Unindent()
        
    End Sub
    
End Class

Açıklamalar

DebugSınıfında hata ayıklama bilgilerini yazdırmak ve mantığınızı denetlemek için yöntemler kullanırsanız, sevk ürününüzün performansını ve kod boyutunu etkilemeden kodunuzun daha sağlam olmasını sağlayabilirsiniz.If you use methods in the Debug class to print debugging information and check your logic with assertions, you can make your code more robust without impacting the performance and code size of your shipping product.

Bu sınıf Assert , bir iletişim kutusu görüntüleme ve her zaman başarısız olacak bir onaylama yayma için yöntemler sağlar.This class provides methods to display an Assert dialog box, and to emit an assertion that will always fail. Bu sınıf, aşağıdaki çeşitlemelerdeki yazma yöntemleri sağlar Write : WriteLine , WriteIf ve WriteLineIf .This class provides write methods in the following variations: Write, WriteLine, WriteIf and WriteLineIf.

BooleanSwitchVe TraceSwitch sınıfları, izleme çıkışını dinamik olarak denetlemek için araçlar sağlar.The BooleanSwitch and TraceSwitch classes provide means to dynamically control the tracing output. Uygulamanızı yeniden derlemeden bu anahtarların değerlerini değiştirebilirsiniz.You can modify the values of these switches without recompiling your application. Anahtar ayarlamak için yapılandırma dosyasını kullanma hakkında daha fazla bilgi için Switch sınıfı ve izleme anahtarları konusuna bakın.For information on using the configuration file to set a switch, see the Switch class and the Trace Switches topic.

Koleksiyona örnek ekleyerek TraceListener veya koleksiyondan örnek kaldırarak izleme çıktısının hedefini özelleştirebilirsiniz Listeners .You can customize the tracing output's target by adding TraceListener instances to or removing instances from the Listeners collection. ListenersKoleksiyon hem hem de sınıfları tarafından paylaşılır Debug Trace ; her iki sınıfa bir izleme dinleyicisi eklemek dinleyiciyi her ikisine de ekler.The Listeners collection is shared by both the Debug and the Trace classes; adding a trace listener to either class adds the listener to both. Varsayılan olarak, DefaultTraceListener sınıfı izleme çıkışını yayar.By default, the DefaultTraceListener class emits trace output.

Not

Koleksiyon için bir izleme dinleyicisi eklemek Listeners , izleme dinleyicisi tarafından kullanılan bir kaynak kullanılabilir değilse izleme sırasında bir özel durumun oluşturulmasına neden olabilir.Adding a trace listener to the Listeners collection can cause an exception to be thrown while tracing, if a resource used by the trace listener is not available. Oluşturulan koşullar ve özel durum, izleme dinleyicisine bağlıdır ve bu konuda numaralandırılamıyor.The conditions and the exception thrown depend on the trace listener and cannot be enumerated in this topic. Debug try / catch İzleme dinleyicilerinin özel durumlarını algılamak ve işlemek için bloklardaki yöntemlere çağrı koymak faydalı olabilir.It may be useful to place calls to the Debug methods in try/catch blocks to detect and handle any exceptions from trace listeners.

Girinti düzeyini Indent yöntemini veya özelliğini kullanarak değiştirebilirsiniz IndentLevel .You can modify the level of indentation using the Indent method or the IndentLevel property. Girinti aralığını değiştirmek için IndentSize özelliğini kullanın.To modify the indent spacing, use the IndentSize property. Özelliğini olarak ayarlayarak, her yazma işleminden sonra çıkış arabelleğinin otomatik olarak temizlenip temizlenmeyeceğini belirtebilirsiniz AutoFlush true .You can specify whether to automatically flush the output buffer after each write by setting the AutoFlush property to true.

AutoFlushVe için ayarlamak için IndentSize Debug uygulamanızın adına karşılık gelen yapılandırma dosyasını düzenleyebilirsiniz.To set the AutoFlush and IndentSize for Debug, you can edit the configuration file corresponding to the name of your application. Yapılandırma dosyası, aşağıdaki örnekte gösterildiği gibi biçimlendirilmelidir.The configuration file should be formatted as shown in the following example.

<configuration>  
  <system.diagnostics>  
    <trace autoflush="true" indentsize="7" />  
  </system.diagnostics>  
</configuration>  

ConditionalAttributeÖzniteliği, yöntemlerine uygulanır Debug .The ConditionalAttribute attribute is applied to the methods of Debug. ConditionalAttribute"Hata ayıklama" bir koşullu derleme sembolü olarak tanımlanmadığı sürece bu yöntemlere yönelik çağrıları yoksay 'ı destekleyen derleyiciler.Compilers that support ConditionalAttribute ignore calls to these methods unless "DEBUG" is defined as a conditional compilation symbol. ConditionalAttributeDesteklenip desteklenmediğini ve koşullu derleme sembolünü tanımlamaya yönelik sözdizimini öğrenmek için bir derleyicinin belgelerine bakın.Refer to a compiler's documentation to determine whether ConditionalAttribute is supported and the syntax for defining a conditional compilation symbol.

Not

Visual Studio C# ve Visual Basic projelerinde, varsayılan olarak, hata ayıklama derlemeleri için "DEBUG" koşullu derleme simgesi tanımlanmıştır ve "TRACE" simgesi hem hata ayıklama hem de yayın yapıları için tanımlanır.In Visual Studio C# and Visual Basic projects, by default, the "DEBUG" conditional compilation symbol is defined for debug builds, and the "TRACE" symbol is defined for both debug and release builds. Bu davranışı devre dışı bırakma hakkında daha fazla bilgi için bkz. Visual Studio belgeleri.For information about how to disable this behavior, see the Visual Studio documentation. Visual C++ 'de koşullu hata ayıklama hakkında daha fazla bilgi için bkz. Debug Class (C++/CLI).For information about conditional debugging in Visual C++, see Debug Class (C++/CLI).

C# ' de "hata AYıKLA" koşullu derleme sembolünü tanımlamak için, /d:DEBUG bir komut satırı kullanarak kodunuzu derlerken derleyici komut satırına seçeneği ekleyin veya #define DEBUG dosyanızın en üstüne ekleyin.To define the "DEBUG" conditional compilation symbol in C#, add the /d:DEBUG option to the compiler command line when you compile your code using a command line, or add #define DEBUG to the top of your file. Visual Basic, /d:DEBUG=True derleyici komut satırına seçeneği ekleyin veya #Const DEBUG=True dosyaya ekleyin.In Visual Basic, add the /d:DEBUG=True option to the compiler command line or add #Const DEBUG=True to the file.

Özellikler

AutoFlush

Flush()Her yazma işleminden sonra çağrılması gerekip gerekmediğini gösteren bir değer alır veya ayarlar Listeners .Gets or sets a value indicating whether Flush() should be called on the Listeners after every write.

IndentLevel

Girinti düzeyini alır veya ayarlar.Gets or sets the indent level.

IndentSize

Girintideki boşluk sayısını alır veya ayarlar.Gets or sets the number of spaces in an indent.

Listeners

Hata ayıklama çıkışını izleyen dinleyicilerinin koleksiyonunu alır.Gets the collection of listeners that is monitoring the debug output.

Yöntemler

Assert(Boolean)

Bir koşulu denetler; Koşul ise false , çağrı yığınını gösteren bir ileti kutusu görüntüler.Checks for a condition; if the condition is false, displays a message box that shows the call stack.

Assert(Boolean, String)

Bir koşulu denetler; Koşul ise false , belirtilen bir ileti verir ve çağrı yığınını gösteren bir ileti kutusu görüntüler.Checks for a condition; if the condition is false, outputs a specified message and displays a message box that shows the call stack.

Assert(Boolean, String, String)

Bir koşulu denetler; Koşul ise false , belirtilen iki iletiyi verir ve çağrı yığınını gösteren bir ileti kutusu görüntüler.Checks for a condition; if the condition is false, outputs two specified messages and displays a message box that shows the call stack.

Assert(Boolean, String, String, Object[])

Bir koşulu denetler; Koşul ise false , iki ileti verir (basit ve biçimlendirilmiştir) ve çağrı yığınını gösteren bir ileti kutusu görüntüler.Checks for a condition; if the condition is false, outputs two messages (simple and formatted) and displays a message box that shows the call stack.

Close()

Çıktı arabelleğini boşaltır ve Close her bir üzerinde yöntemini çağırır Listeners .Flushes the output buffer and then calls the Close method on each of the Listeners.

Fail(String)

Belirtilen hata iletisini yayar.Emits the specified error message.

Fail(String, String)

Bir hata iletisi ve ayrıntılı bir hata iletisi yayar.Emits an error message and a detailed error message.

Flush()

Çıktı arabelleğini temizler ve arabelleğe alınan verilerin koleksiyona yazmasına neden olur Listeners .Flushes the output buffer and causes buffered data to write to the Listeners collection.

Indent()

Geçerli olanı IndentLevel bir artırır.Increases the current IndentLevel by one.

Print(String)

Koleksiyondaki izleme dinleyicilerine bir ileti ve satır Sonlandırıcı yazar Listeners .Writes a message followed by a line terminator to the trace listeners in the Listeners collection.

Print(String, Object[])

Bir satır Sonlandırıcı tarafından izlenen bir biçimli dizeyi, koleksiyondaki izleme dinleyicilerine yazar Listeners .Writes a formatted string followed by a line terminator to the trace listeners in the Listeners collection.

Unindent()

Geçerli olanı IndentLevel bir azaltır.Decreases the current IndentLevel by one.

Write(Object)

Nesnenin ToString() yönteminin değerini koleksiyondaki izleme dinleyicilerine yazar Listeners .Writes the value of the object's ToString() method to the trace listeners in the Listeners collection.

Write(Object, String)

Bir kategori adı ve nesnenin ToString() yönteminin değerini koleksiyondaki izleme dinleyicilerine yazar Listeners .Writes a category name and the value of the object's ToString() method to the trace listeners in the Listeners collection.

Write(String)

Koleksiyondaki izleme dinleyicilerine bir ileti yazar Listeners .Writes a message to the trace listeners in the Listeners collection.

Write(String, String)

Koleksiyondaki izleme dinleyicilerine bir kategori adı ve ileti yazar Listeners .Writes a category name and message to the trace listeners in the Listeners collection.

WriteIf(Boolean, Object)

ToString() Listeners Bir koşul ise, nesne yönteminin değerini koleksiyondaki izleme dinleyicilerine yazar true .Writes the value of the object's ToString() method to the trace listeners in the Listeners collection if a condition is true.

WriteIf(Boolean, Object, String)

Bir koşul ise, bir kategori adı ve nesnenin yönteminin değerini ToString() koleksiyondaki izleme dinleyicilerine yazar Listeners true .Writes a category name and the value of the object's ToString() method to the trace listeners in the Listeners collection if a condition is true.

WriteIf(Boolean, String)

Koşul varsa koleksiyondaki izleme dinleyicilerine bir ileti yazar Listeners true .Writes a message to the trace listeners in the Listeners collection if a condition is true.

WriteIf(Boolean, String, String)

Bir koşul ise koleksiyondaki izleme dinleyicilerine bir kategori adı ve ileti yazar Listeners true .Writes a category name and message to the trace listeners in the Listeners collection if a condition is true.

WriteLine(Object)

Nesnenin ToString() yönteminin değerini koleksiyondaki izleme dinleyicilerine yazar Listeners .Writes the value of the object's ToString() method to the trace listeners in the Listeners collection.

WriteLine(Object, String)

Bir kategori adı ve nesnenin ToString() yönteminin değerini koleksiyondaki izleme dinleyicilerine yazar Listeners .Writes a category name and the value of the object's ToString() method to the trace listeners in the Listeners collection.

WriteLine(String)

Koleksiyondaki izleme dinleyicilerine bir ileti ve satır Sonlandırıcı yazar Listeners .Writes a message followed by a line terminator to the trace listeners in the Listeners collection.

WriteLine(String, Object[])

Bir satır Sonlandırıcı tarafından izlenen, koleksiyondaki izleme dinleyicilerine bir biçimli ileti yazar Listeners .Writes a formatted message followed by a line terminator to the trace listeners in the Listeners collection.

WriteLine(String, String)

Koleksiyondaki izleme dinleyicilerine bir kategori adı ve ileti yazar Listeners .Writes a category name and message to the trace listeners in the Listeners collection.

WriteLineIf(Boolean, Object)

ToString() Listeners Bir koşul ise, nesne yönteminin değerini koleksiyondaki izleme dinleyicilerine yazar true .Writes the value of the object's ToString() method to the trace listeners in the Listeners collection if a condition is true.

WriteLineIf(Boolean, Object, String)

Bir koşul ise, bir kategori adı ve nesnenin yönteminin değerini ToString() koleksiyondaki izleme dinleyicilerine yazar Listeners true .Writes a category name and the value of the object's ToString() method to the trace listeners in the Listeners collection if a condition is true.

WriteLineIf(Boolean, String)

Koşul varsa koleksiyondaki izleme dinleyicilerine bir ileti yazar Listeners true .Writes a message to the trace listeners in the Listeners collection if a condition is true.

WriteLineIf(Boolean, String, String)

Bir koşul ise koleksiyondaki izleme dinleyicilerine bir kategori adı ve ileti yazar Listeners true .Writes a category name and message to the trace listeners in the Listeners collection if a condition is true.

Şunlara uygulanır

İş Parçacığı Güvenliği

Bu güvenli iş parçacığı türüdür.This type is thread safe.

Ayrıca bkz.