Partilhar via


Debug.WriteLine Método

Definição

Grava informações sobre a depuração para os ouvintes de rastreamento na coleção Listeners.

Sobrecargas

WriteLine(String, String)

Grava um nome de categoria e uma mensagem para os ouvintes de rastreamento na coleção Listeners.

WriteLine(String, Object[])

Grava uma mensagem formatada seguida por um terminador de linha para os ouvintes de rastreamento na coleção Listeners.

WriteLine(String)

Grava uma mensagem seguida por um terminador de linha para os ouvintes de rastreamento na coleção Listeners.

WriteLine(Object)

Grava o valor do método ToString() do objeto nos ouvintes de rastreamento na coleção Listeners.

WriteLine(Object, String)

Grava um nome de categoria e o valor do método ToString() do objeto para os ouvintes de rastreamento na coleção Listeners.

WriteLine(String, String)

Origem:
Debug.cs
Origem:
Debug.cs
Origem:
Debug.cs

Grava um nome de categoria e uma mensagem para os ouvintes de rastreamento na coleção Listeners.

public:
 static void WriteLine(System::String ^ message, System::String ^ category);
[System.Diagnostics.Conditional("DEBUG")]
public static void WriteLine (string message, string category);
[System.Diagnostics.Conditional("DEBUG")]
public static void WriteLine (string? message, string? category);
[<System.Diagnostics.Conditional("DEBUG")>]
static member WriteLine : string * string -> unit
Public Shared Sub WriteLine (message As String, category As String)

Parâmetros

message
String

Uma mensagem a ser gravada.

category
String

Um nome de categoria usado para organizar a saída.

Atributos

Exemplos

O exemplo a seguir cria um TraceSwitch chamado generalSwitch. Essa opção é definida fora do exemplo de código.

Se a opção estiver definida como TraceLevelError ou superior, o exemplo gerará a primeira mensagem de erro para o Listeners. Para obter informações sobre como adicionar um ouvinte à coleção Listeners, consulte a classe TraceListenerCollection.

Em seguida, se o TraceLevel estiver definido como Verbose, o exemplo gerará a segunda mensagem de erro e o category na mesma linha que a primeira mensagem. Um terminador de linha segue a segunda mensagem.

   // Class-level declaration.
   // Create a TraceSwitch.
   static TraceSwitch^ generalSwitch = 
      gcnew TraceSwitch( "General","Entire Application" );

public:
   static void MyErrorMethod( String^ category )
   {
      // Write the message if the TraceSwitch level is set to Error or higher.
      if ( generalSwitch->TraceError )
      {
         #if defined(DEBUG)
         Debug::Write( "My error message. " );
         #endif
      }
      // Write a second message if the TraceSwitch level is set to Verbose.
      if ( generalSwitch->TraceVerbose )
      {
         #if defined(DEBUG)
         Debug::WriteLine( "My second error message.", category );
         #endif
      }
   }
// Class-level declaration.
// Create a TraceSwitch.
static TraceSwitch generalSwitch = new TraceSwitch("General", "Entire Application");

static public void MyErrorMethod(string category)
{
    // Write the message if the TraceSwitch level is set to Error or higher.
    if (generalSwitch.TraceError)
        Debug.Write("My error message. ");

    // Write a second message if the TraceSwitch level is set to Verbose.
    if (generalSwitch.TraceVerbose)
        Debug.WriteLine("My second error message.", category);
}
' Class-level declaration.
' Create a TraceSwitch.
Private Shared generalSwitch As New TraceSwitch("General", "Entire Application")


Public Shared Sub MyErrorMethod(category As String)
    ' Write the message if the TraceSwitch level is set to Error or higher.
    If generalSwitch.TraceError Then
        Debug.Write("My error message. ")
    End If 
    ' Write a second message if the TraceSwitch level is set to Verbose.
    If generalSwitch.TraceVerbose Then
        Debug.WriteLine("My second error message.", category)
    End If
End Sub

Comentários

Por padrão, a saída é gravada em uma instância de DefaultTraceListener.

O parâmetro category pode ser usado para agrupar mensagens de saída.

Esse método chama o método WriteLine do ouvinte de rastreamento.

Confira também

Aplica-se a

WriteLine(String, Object[])

Origem:
Debug.cs
Origem:
Debug.cs
Origem:
Debug.cs

Grava uma mensagem formatada seguida por um terminador de linha para os ouvintes de rastreamento na coleção Listeners.

public:
 static void WriteLine(System::String ^ format, ... cli::array <System::Object ^> ^ args);
[System.Diagnostics.Conditional("DEBUG")]
public static void WriteLine (string format, params object[] args);
[System.Diagnostics.Conditional("DEBUG")]
public static void WriteLine (string format, params object?[] args);
[<System.Diagnostics.Conditional("DEBUG")>]
static member WriteLine : string * obj[] -> unit
Public Shared Sub WriteLine (format As String, ParamArray args As Object())

Parâmetros

format
String

Uma cadeia de caracteres de formato composto que contém texto intermixado com zero ou mais itens de formato, que correspondem a objetos na matriz args.

args
Object[]

Uma matriz de objetos que contém zero ou mais objetos a serem formatados.

Atributos

Comentários

Esse método usa o recurso de formatação composta do .NET para converter o valor de um objeto em sua representação de texto e inserir essa representação em uma cadeia de caracteres.

A palavra-chave (em C#) ou ParamArray (no Visual Basic) na sintaxe desse método implica que a matriz de objetos pode ser um único valor. A exceção a isso é o objeto String. Sobrecargas explícitas têm precedência, portanto, um valor arg de uma única cadeia de caracteres será padrão para a sobrecarga de Debug.WriteLine(String, String).

Por padrão, a saída é gravada em uma instância de DefaultTraceListener.

Esse método chama o método TraceListener.WriteLine do ouvinte de rastreamento.

Aplica-se a

WriteLine(String)

Origem:
Debug.cs
Origem:
Debug.cs
Origem:
Debug.cs

Grava uma mensagem seguida por um terminador de linha para os ouvintes de rastreamento na coleção Listeners.

public:
 static void WriteLine(System::String ^ message);
[System.Diagnostics.Conditional("DEBUG")]
public static void WriteLine (string message);
[System.Diagnostics.Conditional("DEBUG")]
public static void WriteLine (string? message);
[<System.Diagnostics.Conditional("DEBUG")>]
static member WriteLine : string -> unit
Public Shared Sub WriteLine (message As String)

Parâmetros

message
String

Uma mensagem a ser gravada.

Atributos

Exemplos

O exemplo a seguir cria um TraceSwitch chamado generalSwitch. Essa opção é definida fora do exemplo de código.

Se a opção estiver definida como TraceLevelError ou superior, o exemplo gerará a primeira mensagem de erro para o Listeners. Para obter informações sobre como adicionar um ouvinte à coleção Listeners, consulte a classe TraceListenerCollection.

Em seguida, se o TraceLevel estiver definido como Verbose, o exemplo gerará a segunda mensagem de erro na mesma linha que a primeira mensagem. Um terminador de linha segue a segunda mensagem.

   // Class-level declaration.
   // Create a TraceSwitch.
   static TraceSwitch^ generalSwitch = 
      gcnew TraceSwitch( "General","Entire Application" );

public:
   static void MyErrorMethod()
   {
      // Write the message if the TraceSwitch level is set to Error or higher.
      if ( generalSwitch->TraceError )
      {
         #if defined(DEBUG)
         Debug::Write( "My error message. " );
         #endif
      }
      // Write a second message if the TraceSwitch level is set to Verbose.
      if ( generalSwitch->TraceVerbose )
      {
         #if defined(DEBUG)
         Debug::WriteLine( "My second error message." );
         #endif
      }
   }
// Class-level declaration.
// Create a TraceSwitch.
TraceSwitch generalSwitch = new TraceSwitch("General", "Entire Application");

static void MyErrorMethod()
{
    // Write the message if the TraceSwitch level is set to Error or higher.
    if (generalSwitch.TraceError)
        Debug.Write("My error message. ");

    // Write a second message if the TraceSwitch level is set to Verbose.
    if (generalSwitch.TraceVerbose)
        Debug.WriteLine("My second error message.");
}
' Class-level declaration.
' Create a TraceSwitch.
Private Shared generalSwitch As New TraceSwitch("General", "Entire Application")


Public Shared Sub MyErrorMethod()
    ' Write the message if the TraceSwitch level is set to Error or higher.
    If generalSwitch.TraceError Then
        Debug.Write("My error message. ")
    End If 
    ' Write a second message if the TraceSwitch level is set to Verbose.
    If generalSwitch.TraceVerbose Then
        Debug.WriteLine("My second error message.")
    End If
End Sub

Comentários

Por padrão, a saída é gravada em uma instância de DefaultTraceListener.

Esse método chama o método WriteLine do ouvinte de rastreamento.

Confira também

Aplica-se a

WriteLine(Object)

Origem:
Debug.cs
Origem:
Debug.cs
Origem:
Debug.cs

Grava o valor do método ToString() do objeto nos ouvintes de rastreamento na coleção Listeners.

public:
 static void WriteLine(System::Object ^ value);
[System.Diagnostics.Conditional("DEBUG")]
public static void WriteLine (object value);
[System.Diagnostics.Conditional("DEBUG")]
public static void WriteLine (object? value);
[<System.Diagnostics.Conditional("DEBUG")>]
static member WriteLine : obj -> unit
Public Shared Sub WriteLine (value As Object)

Parâmetros

value
Object

Um objeto cujo nome é enviado para o Listeners.

Atributos

Exemplos

O exemplo a seguir cria um TraceSwitch chamado generalSwitch. Essa opção é definida fora do exemplo de código.

Se a opção estiver definida como TraceLevelError ou superior, o exemplo gerará a primeira mensagem de erro para o Listeners. Para obter informações sobre como adicionar um ouvinte à coleção Listeners, consulte a classe TraceListenerCollection.

Em seguida, se o TraceLevel estiver definido como Verbose, o exemplo produzirá o nome do objeto na mesma linha que a primeira mensagem. Um terminador de linha segue a segunda mensagem.

   // Class-level declaration.
   // Create a TraceSwitch.
   static TraceSwitch^ generalSwitch = 
      gcnew TraceSwitch( "General","Entire Application" );

public:
   static void MyErrorMethod( Object^ myObject )
   {
      // Write the message if the TraceSwitch level is set to Error or higher.
      if ( generalSwitch->TraceError )
      {
         #if defined(DEBUG)
         Debug::Write( "Invalid object. " );
         #endif
      }
      // Write a second message if the TraceSwitch level is set to Verbose.
      if ( generalSwitch->TraceVerbose )
      {
         #if defined(DEBUG)
         Debug::WriteLine( myObject );
         #endif
      }
   }
// Class-level declaration.
// Create a TraceSwitch.
static TraceSwitch generalSwitch = new TraceSwitch("General", "Entire Application");

static public void MyErrorMethod(Object myObject)
{
    // Write the message if the TraceSwitch level is set to Error or higher.
    if (generalSwitch.TraceError)
        Debug.Write("Invalid object. ");

    // Write a second message if the TraceSwitch level is set to Verbose.
    if (generalSwitch.TraceVerbose)
        Debug.WriteLine(myObject);
}
' Class-level declaration.
' Create a TraceSwitch.
Private Shared generalSwitch As New TraceSwitch("General", "Entire Application")


Public Shared Sub MyErrorMethod(myObject As Object)
    ' Write the message if the TraceSwitch level is set to Error or higher.
    If generalSwitch.TraceError Then
        Debug.Write("Invalid object. ")
    End If 
    ' Write a second message if the TraceSwitch level is set to Verbose.
    If generalSwitch.TraceVerbose Then
        Debug.WriteLine(myObject)
    End If
End Sub

Comentários

Por padrão, a saída é gravada em uma instância de DefaultTraceListener.

Esse método chama o método WriteLine do ouvinte de rastreamento.

Confira também

Aplica-se a

WriteLine(Object, String)

Origem:
Debug.cs
Origem:
Debug.cs
Origem:
Debug.cs

Grava um nome de categoria e o valor do método ToString() do objeto para os ouvintes de rastreamento na coleção Listeners.

public:
 static void WriteLine(System::Object ^ value, System::String ^ category);
[System.Diagnostics.Conditional("DEBUG")]
public static void WriteLine (object value, string category);
[System.Diagnostics.Conditional("DEBUG")]
public static void WriteLine (object? value, string? category);
[<System.Diagnostics.Conditional("DEBUG")>]
static member WriteLine : obj * string -> unit
Public Shared Sub WriteLine (value As Object, category As String)

Parâmetros

value
Object

Um objeto cujo nome é enviado para o Listeners.

category
String

Um nome de categoria usado para organizar a saída.

Atributos

Exemplos

O exemplo a seguir cria um TraceSwitch chamado generalSwitch. Essa opção é definida fora do exemplo de código.

Se a opção estiver definida como TraceLevelError ou superior, o exemplo gerará a primeira mensagem de erro para o Listeners. Para obter informações sobre como adicionar um ouvinte à coleção Listeners, consulte a classe TraceListenerCollection.

Em seguida, se o TraceLevel estiver definido como Verbose, o exemplo gerará a segunda mensagem de erro na mesma linha que a primeira mensagem. A segunda mensagem é seguida por um terminador de linha.

   // Class-level declaration.
   // Create a TraceSwitch.
   static TraceSwitch^ generalSwitch = 
      gcnew TraceSwitch( "General","Entire Application" );

public:
   static void MyErrorMethod( Object^ myObject, String^ category )
   {
      // Write the message if the TraceSwitch level is set to Error or higher.
      if ( generalSwitch->TraceError )
      {
         #if defined(DEBUG)
         Debug::Write( "Invalid object for category. " );
         #endif
      }
      // Write a second message if the TraceSwitch level is set to Verbose.
      if ( generalSwitch->TraceVerbose )
      {
         #if defined(DEBUG)
         Debug::WriteLine( myObject, category );
         #endif
      }
   }
// Class-level declaration.
// Create a TraceSwitch.
static TraceSwitch generalSwitch = new TraceSwitch("General", "Entire Application");

static public void MyErrorMethod(Object myObject, string category)
{
    // Write the message if the TraceSwitch level is set to Error or higher.
    if (generalSwitch.TraceError)
        Debug.Write("Invalid object for category. ");

    // Write a second message if the TraceSwitch level is set to Verbose.
    if (generalSwitch.TraceVerbose)
        Debug.WriteLine(myObject, category);
}
' Class-level declaration.
' Create a TraceSwitch.
Private Shared generalSwitch As New TraceSwitch("General", "Entire Application")


Public Shared Sub MyErrorMethod(myObject As Object, category As String)
    ' Write the message if the TraceSwitch level is set to Error or higher.
    If generalSwitch.TraceError Then
        Debug.Write("Invalid object for category. ")
    End If 
    ' Write a second message if the TraceSwitch level is set to Verbose.
    If generalSwitch.TraceVerbose Then
        Debug.WriteLine(myObject, category)
    End If
End Sub

Comentários

Por padrão, a saída é gravada em uma instância de DefaultTraceListener.

O parâmetro category pode ser usado para agrupar mensagens de saída.

Esse método chama o método WriteLine do ouvinte de rastreamento.

Confira também

Aplica-se a