Questo articolo è stato tradotto automaticamente. Per visualizzare l'articolo in inglese, selezionare la casella di controllo Inglese. È possibile anche visualizzare il testo inglese in una finestra popup posizionando il puntatore del mouse sopra il testo.
Traduzione
Inglese

Metodo Trace.Write (String, String)

 

Scrive un nome di categoria e un messaggio nei listener di traccia della raccolta Listeners.

Spazio dei nomi:   System.Diagnostics
Assembly:  System (in System.dll)

[ConditionalAttribute("TRACE")]
public static void Write(
	string message,
	string category
)

Parametri

message
Type: System.String

Messaggio da scrivere.

category
Type: System.String

Nome di categoria usato per organizzare l'output.

By default, the output is written to an instance of T:System.Diagnostics.DefaultTraceListener.

The category parameter can be used to group output messages.

This method calls the M:System.Diagnostics.TraceListener.Write(System.String) method of the trace listener.

System_CAPS_noteNota

ASP.NET supplies tracing functionality tailored for Web pages. To write trace messages in ASP.NET pages, use the P:System.Web.UI.Page.Trace property.

By default, in code associated with an ASP.NET Web page, the statement Trace.Write("...") is a call to the Overload:System.Web.TraceContext.Write method of the P:System.Web.UI.Page.Trace property. To use the T:System.Diagnostics.Trace class in Web pages, you must include the namespace, for example, System.Diagnostics.Trace.Write("...").

The following example creates a T:System.Diagnostics.TraceSwitch named generalSwitch. This switch is set outside the code sample.

If the switch is set to the T:System.Diagnostics.TraceLevelVerbose, the example outputs the first error message to the P:System.Diagnostics.Trace.Listeners. For information on adding a listener to the P:System.Diagnostics.Trace.Listeners collection, see the T:System.Diagnostics.TraceListenerCollection class.

Then, if the T:System.Diagnostics.TraceLevel is set to Error or higher, the example outputs the second error message on the same line as the first message. The second message is followed by a line terminator.

// 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 Verbose.
    if(generalSwitch.TraceVerbose)
       Trace.Write(myObject.ToString() + " is not a valid object for category: ", 
          category);

    // Write a second message if the TraceSwitch level is set to Error or higher.
    if(generalSwitch.TraceError)
       Trace.WriteLine(" Please use a different category.");
 }

.NET Framework
Disponibile da 1.1
Torna all'inizio
Mostra: