TextWriterTraceListener Třída
Definice
Směruje trasování nebo ladění výstupu do TextWriter nebo do Stream , například FileStream .Directs tracing or debugging output to a TextWriter or to a Stream, such as FileStream.
public ref class TextWriterTraceListener : System::Diagnostics::TraceListener
public class TextWriterTraceListener : System.Diagnostics.TraceListener
type TextWriterTraceListener = class
inherit TraceListener
Public Class TextWriterTraceListener
Inherits TraceListener
- Dědičnost
- Dědičnost
- Odvozené
Příklady
V následujícím příkladu je implementována instance TextWriterTraceListener třídy, která používá StreamWriter volání myOutputWriter k zápisu do souboru s názvem TestFile.txt .The following example implements an instance of the TextWriterTraceListener class that uses a StreamWriter called myOutputWriter to write to a file named TestFile.txt. Nejprve příklad vytvoří soubor pro výstup.First the example creates a file for output. Potom vytvoří StreamWriter pro první zapisovač textu, přiřadí ho do výstupního souboru a přidá ho do Listeners .Then it creates the StreamWriter for the first text writer, assigns it the output file, and adds it to the Listeners. Kód potom vytvoří výstup jednoho řádku textu do souboru.Then, the code outputs one line of text to the file. Nakonec tento příklad vyprázdní výstupní vyrovnávací paměť.Finally, the example flushes the output buffer.
Po spuštění této ukázky můžete otevřít TestFile.txt soubor a zobrazit výstup.After running this sample, you can open the TestFile.txt file to see the output.
void main()
{
#if defined(TRACE)
// Create a file for output named TestFile.txt.
Stream^ myFile = File::Create( "TestFile.txt" );
// Create a new text writer using the output stream and
// add it to the trace listeners.
TextWriterTraceListener^ myTextListener =
gcnew TextWriterTraceListener( myFile );
Trace::Listeners->Add( myTextListener );
// Write output to the file.
Trace::Write( "Test output " );
// Flush the output.
Trace::Flush();
Trace::Close();
#endif
}
public class Sample
{
public static int Main(string[] args) {
// Create a file for output named TestFile.txt.
Stream myFile = File.Create("TestFile.txt");
/* Create a new text writer using the output stream, and add it to
* the trace listeners. */
TextWriterTraceListener myTextListener = new
TextWriterTraceListener(myFile);
Trace.Listeners.Add(myTextListener);
// Write output to the file.
Trace.Write("Test output ");
// Flush the output.
Trace.Flush();
return 0;
}
}
Public Class Sample
Public Shared Sub Main()
' Create a file for output named TestFile.txt.
Dim myFile As Stream = File.Create("TestFile.txt")
' Create a new text writer using the output stream, and add it to
' the trace listeners.
Dim myTextListener As New TextWriterTraceListener(myFile)
Trace.Listeners.Add(myTextListener)
' Write output to the file.
Trace.Write("Test output ")
' Flush the output.
Trace.Flush()
System.Environment.ExitCode = 0
End Sub
End Class
Poznámky
TextWriterTraceListenerTřída poskytuje Writer vlastnost pro získání nebo nastavení zapisovače textu, který přijímá výstup trasování nebo ladění.The TextWriterTraceListener class provides the Writer property to get or set the text writer that receives the tracing or debugging output.
Důležité
Tento typ implementuje IDisposable rozhraní.This type implements the IDisposable interface. Po dokončení používání typu byste ho měli nakládat buď přímo, nebo nepřímo.When you have finished using the type, you should dispose of it either directly or indirectly. Chcete-li přímo uvolnit typ, zavolejte jeho Dispose metodu v try / catch bloku.To dispose of the type directly, call its Dispose method in a try/catch block. Chcete-li ji nakládat nepřímo, použijte konstrukci jazyka, například using (v jazyce C#) nebo Using (v Visual Basic).To dispose of it indirectly, use a language construct such as using (in C#) or Using (in Visual Basic). Další informace naleznete v části "použití objektu, který implementuje IDisposable" v IDisposable tématu rozhraní.For more information, see the "Using an Object that Implements IDisposable" section in the IDisposable interface topic.
Tato třída také poskytuje metody pro Close Writer , aby již nepřijímaly trasování nebo ladění výstupu, do Flush výstupní vyrovnávací paměti pro Writer a do Write zprávy do Writer .This class also provides methods to Close the Writer so that it no longer receives tracing or debugging output, to Flush the output buffer for the Writer, and to Write a message to the Writer.
Chcete-li použít naslouchací proces trasování, je nutné povolit trasování nebo ladění.You must enable tracing or debugging to use a trace listener. Následující syntaxe je specifická pro kompilátor.The following syntax is compiler specific. Pokud používáte jiné kompilátory než C# nebo Visual Basic, přečtěte si dokumentaci k vašemu kompilátoru.If you use compilers other than C# or Visual Basic, refer to the documentation for your compiler.
Chcete-li povolit ladění v jazyce C#, přidejte
/d:DEBUGpříznak do příkazového řádku kompilátoru při kompilování kódu nebo můžete přidat#define DEBUGdo horní části souboru.To enable debugging in C#, add the/d:DEBUGflag to the compiler command line when you compile your code, or you can add#define DEBUGto the top of your file. V Visual Basic přidejte/d:DEBUG=Truepříznak do příkazového řádku kompilátoru.In Visual Basic, add the/d:DEBUG=Trueflag to the compiler command line.Chcete-li povolit trasování v jazyce C#, přidejte
/d:TRACEpříznak do příkazového řádku kompilátoru při kompilování kódu nebo přidejte#define TRACEdo horní části souboru.To enable tracing in C#, add the/d:TRACEflag to the compiler command line when you compile your code, or add#define TRACEto the top of your file. V Visual Basic přidejte/d:TRACE=Truepříznak do příkazového řádku kompilátoru.In Visual Basic, add the/d:TRACE=Trueflag to the compiler command line.
Chcete-li přidat naslouchací proces trasování, upravte konfigurační soubor, který odpovídá názvu vaší aplikace.To add a trace listener, edit the configuration file that corresponds to the name of your application. V tomto souboru můžete přidat naslouchací proces, nastavit jeho typ a nastavit jeho parametr, odebrat naslouchací proces, nebo zrušit všechny naslouchací procesy, které dříve nastavila aplikace.Within this file, you can add a listener, set its type and set its parameter, remove a listener, or clear all the listeners previously set by the application. Konfigurační soubor by měl být naformátován podobně jako v následujícím příkladu.The configuration file should be formatted like the following example.
<configuration>
<system.diagnostics>
<trace autoflush="false" indentsize="4">
<listeners>
<add name="myListener"
type="System.Diagnostics.TextWriterTraceListener"
initializeData="TextWriterOutput.log" />
<remove name="Default" />
</listeners>
</trace>
</system.diagnostics>
</configuration>
Poznámka
Pokud je proveden pokus o zápis do souboru, který je používán nebo není k dispozici, název souboru je automaticky předponou identifikátorem GUID.If an attempt is made to write to a file that is in use or unavailable, the file name is automatically prefixed by a GUID.
Konstruktory
| TextWriterTraceListener() |
Inicializuje novou instanci TextWriterTraceListener třídy s TextWriter jako výstupní příjemce.Initializes a new instance of the TextWriterTraceListener class with TextWriter as the output recipient. |
| TextWriterTraceListener(Stream) |
Inicializuje novou instanci TextWriterTraceListener třídy pomocí datového proudu jako příjemce výstupu ladění a trasování.Initializes a new instance of the TextWriterTraceListener class, using the stream as the recipient of the debugging and tracing output. |
| TextWriterTraceListener(Stream, String) |
Inicializuje novou instanci TextWriterTraceListener třídy se zadaným názvem a pomocí datového proudu jako příjemce výstupu ladění a trasování.Initializes a new instance of the TextWriterTraceListener class with the specified name, using the stream as the recipient of the debugging and tracing output. |
| TextWriterTraceListener(String) |
Inicializuje novou instanci TextWriterTraceListener třídy pomocí souboru jako příjemce výstupu ladění a trasování.Initializes a new instance of the TextWriterTraceListener class, using the file as the recipient of the debugging and tracing output. |
| TextWriterTraceListener(String, String) |
Inicializuje novou instanci TextWriterTraceListener třídy se zadaným názvem a pomocí souboru jako příjemce výstupu ladění a trasování.Initializes a new instance of the TextWriterTraceListener class with the specified name, using the file as the recipient of the debugging and tracing output. |
| TextWriterTraceListener(TextWriter) |
Inicializuje novou instanci TextWriterTraceListener třídy pomocí zadaného zapisovače jako příjemce výstupu trasování nebo ladění.Initializes a new instance of the TextWriterTraceListener class using the specified writer as recipient of the tracing or debugging output. |
| TextWriterTraceListener(TextWriter, String) |
Inicializuje novou instanci TextWriterTraceListener třídy se zadaným názvem pomocí zadaného zapisovače jako příjemce výstupu trasování nebo ladění.Initializes a new instance of the TextWriterTraceListener class with the specified name, using the specified writer as recipient of the tracing or debugging output. |
Vlastnosti
| Attributes |
Získá vlastní atributy naslouchacího procesu trasování definované v konfiguračním souboru aplikace.Gets the custom trace listener attributes defined in the application configuration file. (Zděděno od TraceListener) |
| Filter |
Získá nebo nastaví filtr trasování pro naslouchací proces trasování.Gets or sets the trace filter for the trace listener. (Zděděno od TraceListener) |
| IndentLevel |
Získá nebo nastaví úroveň odsazení.Gets or sets the indent level. (Zděděno od TraceListener) |
| IndentSize |
Získá nebo nastaví počet mezer v odsazení.Gets or sets the number of spaces in an indent. (Zděděno od TraceListener) |
| IsThreadSafe |
Načte hodnotu, která označuje, zda je naslouchací proces trasování bezpečný pro přístup z více vláken.Gets a value indicating whether the trace listener is thread safe. (Zděděno od TraceListener) |
| Name |
Získá nebo nastaví název pro tuto hodnotu TraceListener .Gets or sets a name for this TraceListener. (Zděděno od TraceListener) |
| NeedIndent |
Získá nebo nastaví hodnotu označující, zda má být výstup odsazen.Gets or sets a value indicating whether to indent the output. (Zděděno od TraceListener) |
| TraceOutputOptions |
Získá nebo nastaví možnosti výstupu trasování.Gets or sets the trace output options. (Zděděno od TraceListener) |
| Writer |
Získá nebo nastaví zapisovač textu, který přijímá výstup trasování nebo ladění.Gets or sets the text writer that receives the tracing or debugging output. |
Metody
| Close() |
Zavře Writer , aby již nepřijímal trasování nebo ladění výstupu.Closes the Writer so that it no longer receives tracing or debugging output. |
| Close() |
Při přepsání v odvozené třídě zavře výstupní datový proud, takže již nepřijímá trasování nebo ladění výstupu.When overridden in a derived class, closes the output stream so it no longer receives tracing or debugging output. (Zděděno od TraceListener) |
| CreateObjRef(Type) |
Vytvoří objekt, který obsahuje všechny relevantní informace požadované pro vygenerování proxy serveru, který se používá ke komunikaci se vzdáleným objektem.Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object. (Zděděno od MarshalByRefObject) |
| Dispose() |
Uvolní všechny prostředky, které používá TraceListener .Releases all resources used by the TraceListener. (Zděděno od TraceListener) |
| Dispose(Boolean) |
Odstraní tento TextWriterTraceListener objekt.Disposes this TextWriterTraceListener object. |
| Equals(Object) |
Určí, zda se zadaný objekt rovná aktuálnímu objektu.Determines whether the specified object is equal to the current object. (Zděděno od Object) |
| Fail(String) |
Vygeneruje chybovou zprávu pro naslouchací proces, který vytvoříte při implementaci TraceListener třídy.Emits an error message to the listener you create when you implement the TraceListener class. (Zděděno od TraceListener) |
| Fail(String, String) |
Vygeneruje chybovou zprávu a podrobnou chybovou zprávu pro naslouchací proces, který vytvoříte při implementaci TraceListener třídy.Emits an error message and a detailed error message to the listener you create when you implement the TraceListener class. (Zděděno od TraceListener) |
| Flush() |
Vyprázdní výstupní vyrovnávací paměť pro Writer .Flushes the output buffer for the Writer. |
| GetHashCode() |
Slouží jako výchozí funkce hash.Serves as the default hash function. (Zděděno od Object) |
| GetLifetimeService() |
Zastaralé.
Načte aktuální objekt služby životnosti, který řídí zásady životního cyklu pro tuto instanci.Retrieves the current lifetime service object that controls the lifetime policy for this instance. (Zděděno od MarshalByRefObject) |
| GetSupportedAttributes() |
Získá vlastní atributy, které podporuje naslouchací proces trasování.Gets the custom attributes supported by the trace listener. (Zděděno od TraceListener) |
| GetType() |
Získá Type aktuální instanci.Gets the Type of the current instance. (Zděděno od Object) |
| InitializeLifetimeService() |
Zastaralé.
Získá objekt služby životnosti, který řídí zásady životního cyklu pro tuto instanci.Obtains a lifetime service object to control the lifetime policy for this instance. (Zděděno od MarshalByRefObject) |
| MemberwiseClone() |
Vytvoří kopii aktuálního seznamu Object .Creates a shallow copy of the current Object. (Zděděno od Object) |
| MemberwiseClone(Boolean) |
Vytvoří kopii aktuálního objektu bez podstruktury MarshalByRefObject .Creates a shallow copy of the current MarshalByRefObject object. (Zděděno od MarshalByRefObject) |
| ToString() |
Vrátí řetězec, který představuje aktuální objekt.Returns a string that represents the current object. (Zděděno od Object) |
| TraceData(TraceEventCache, String, TraceEventType, Int32, Object) |
Zapisuje trasovací informace, datový objekt a informace o události do výstupu specifického pro naslouchací proces.Writes trace information, a data object and event information to the listener specific output. (Zděděno od TraceListener) |
| TraceData(TraceEventCache, String, TraceEventType, Int32, Object[]) |
Zapisuje trasovací informace, pole datových objektů a informací o událostech do výstupu specifického pro naslouchací proces.Writes trace information, an array of data objects and event information to the listener specific output. (Zděděno od TraceListener) |
| TraceEvent(TraceEventCache, String, TraceEventType, Int32) |
Zapisuje informace o trasování a události do výstupu specifického pro naslouchací proces.Writes trace and event information to the listener specific output. (Zděděno od TraceListener) |
| TraceEvent(TraceEventCache, String, TraceEventType, Int32, String) |
Zapisuje informace o trasování, zprávu a událost do výstupu specifického pro naslouchací proces.Writes trace information, a message, and event information to the listener specific output. (Zděděno od TraceListener) |
| TraceEvent(TraceEventCache, String, TraceEventType, Int32, String, Object[]) |
Zapisuje informace o trasování, formátované pole objektů a informací o událostech na výstup konkrétního naslouchacího procesu.Writes trace information, a formatted array of objects and event information to the listener specific output. (Zděděno od TraceListener) |
| TraceTransfer(TraceEventCache, String, Int32, String, Guid) |
Zapisuje informace o trasování, zprávu, informace o identitě a události související aktivity do výstupního konkrétního naslouchacího procesu.Writes trace information, a message, a related activity identity and event information to the listener specific output. (Zděděno od TraceListener) |
| Write(Object) |
Zapíše hodnotu ToString() metody objektu pro naslouchací proces, který vytvoříte při implementaci TraceListener třídy.Writes the value of the object's ToString() method to the listener you create when you implement the TraceListener class. (Zděděno od TraceListener) |
| Write(Object, String) |
Zapíše název kategorie a hodnotu ToString() metody objektu pro naslouchací proces, který vytvoříte při implementaci TraceListener třídy.Writes a category name and the value of the object's ToString() method to the listener you create when you implement the TraceListener class. (Zděděno od TraceListener) |
| Write(String) |
Zapíše zprávu do této instance Writer .Writes a message to this instance's Writer. |
| Write(String, String) |
Zapíše název kategorie a zprávu do naslouchacího procesu, který vytvoříte při implementaci TraceListener třídy.Writes a category name and a message to the listener you create when you implement the TraceListener class. (Zděděno od TraceListener) |
| WriteIndent() |
Zapíše odsazení do naslouchacího procesu, který vytvoříte při implementaci této třídy, a obnoví NeedIndent vlastnost na |
| WriteLine(Object) |
Zapíše hodnotu ToString() metody objektu pro naslouchací proces, který vytvoříte při implementaci TraceListener třídy následovaný ukončovacím znakem řádku.Writes the value of the object's ToString() method to the listener you create when you implement the TraceListener class, followed by a line terminator. (Zděděno od TraceListener) |
| WriteLine(Object, String) |
Zapíše název kategorie a hodnotu ToString() metody objektu pro naslouchací proces, který vytvoříte při implementaci TraceListener třídy následovaný ukončovacím znakem řádku.Writes a category name and the value of the object's ToString() method to the listener you create when you implement the TraceListener class, followed by a line terminator. (Zděděno od TraceListener) |
| WriteLine(String) |
Zapíše zprávu do této instance Writer následovanou zakončením řádku.Writes a message to this instance's Writer followed by a line terminator. Výchozí zakončení řádku je návratový znak následovaný řádkovým kanálem (\r\n).The default line terminator is a carriage return followed by a line feed (\r\n). |
| WriteLine(String, String) |
Zapíše název kategorie a zprávu do naslouchacího procesu, který vytvoříte při implementaci TraceListener třídy následovaný ukončovacím znakem řádku.Writes a category name and a message to the listener you create when you implement the TraceListener class, followed by a line terminator. (Zděděno od TraceListener) |