TextWriterTraceListener Sınıf
Tanım
İzleme veya hata ayıklama çıkışını bir TextWriter veya gibi bir öğesine yönlendirir Stream 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
- Devralma
- Devralma
- Türetilmiş
Örnekler
Aşağıdaki örnek, TextWriterTraceListener StreamWriter adlı bir myOutputWriter dosyaya yazmak için çağrılan bir sınıfının örneğini uygular 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. Önce örnek, çıkış için bir dosya oluşturur.First the example creates a file for output. Ardından, StreamWriter ilk metin yazıcısı için öğesini oluşturur, çıkış dosyasını atar ve öğesine ekler Listeners .Then it creates the StreamWriter for the first text writer, assigns it the output file, and adds it to the Listeners. Daha sonra kod, dosyaya bir satırlık metin verir.Then, the code outputs one line of text to the file. Son olarak, örnek çıktı arabelleğini temizler.Finally, the example flushes the output buffer.
Bu örneği çalıştırdıktan sonra TestFile.txt çıktıyı görmek için dosyasını açabilirsiniz.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
Açıklamalar
TextWriterTraceListenerSınıfı, Writer izleme veya hata ayıklama çıkışını alan metin yazıcısını almak veya ayarlamak için özelliğini sağlar.The TextWriterTraceListener class provides the Writer property to get or set the text writer that receives the tracing or debugging output.
Önemli
Bu tür, IDisposable arabirimini uygular.This type implements the IDisposable interface. Türü kullanmayı bitirdiğinizde, bunu doğrudan veya dolaylı olarak atabilirsiniz.When you have finished using the type, you should dispose of it either directly or indirectly. Türü doğrudan atmak için, Dispose yöntemini bir try / catch blokta çağırın.To dispose of the type directly, call its Dispose method in a try/catch block. Dolaylı olarak atmak için using (C# dilinde) veya (Visual Basic) gibi bir dil yapısı kullanın Using .To dispose of it indirectly, use a language construct such as using (in C#) or Using (in Visual Basic). Daha fazla bilgi için, interface konusunun "IDisposable uygulayan bir nesne kullanma" bölümüne bakın IDisposable .For more information, see the "Using an Object that Implements IDisposable" section in the IDisposable interface topic.
Bu sınıf Ayrıca, için Close Writer bir izleme veya hata ayıklama çıktısı, için Flush Çıkış arabelleğine Writer ve Write öğesine bir ileti almak Writer için yöntemler sağlar.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.
İzleme dinleyicisi kullanmak için izlemeyi veya hata ayıklamayı etkinleştirmeniz gerekir.You must enable tracing or debugging to use a trace listener. Aşağıdaki sözdizimi derleyiciye özeldir.The following syntax is compiler specific. C# veya Visual Basic dışında derleyiciler kullanıyorsanız, derleyicinizi için belgelere bakın.If you use compilers other than C# or Visual Basic, refer to the documentation for your compiler.
C# ' de hata ayıklamayı etkinleştirmek için,
/d:DEBUGkodunuzu derlerken derleyiciyi derleyici komut satırına ekleyin veya#define DEBUGdosyanızın en üstüne ekleyin.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. Visual Basic ' de,/d:DEBUG=Truebayrağını derleyici komut satırına ekleyin.In Visual Basic, add the/d:DEBUG=Trueflag to the compiler command line.C# ' de izlemeyi etkinleştirmek için,
/d:TRACEkodunuzu derlerken derleyici komut satırına bayrağı ekleyin veya#define TRACEdosyanızın en üstüne ekleyin.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. Visual Basic ' de,/d:TRACE=Truebayrağını derleyici komut satırına ekleyin.In Visual Basic, add the/d:TRACE=Trueflag to the compiler command line.
Bir izleme dinleyicisi eklemek için uygulamanızın adına karşılık gelen yapılandırma dosyasını düzenleyin.To add a trace listener, edit the configuration file that corresponds to the name of your application. Bu dosya içinde bir dinleyici ekleyebilir, türünü ayarlayabilir ve parametresini ayarlayabilir, bir dinleyiciyi kaldırabilir ya da uygulama tarafından daha önce ayarlanmış tüm dinleyicileri temizleyebilirsiniz.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. Yapılandırma dosyası aşağıdaki örnekteki gibi biçimlendirilmelidir.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>
Not
Kullanımda olan veya kullanılamayan bir dosyaya yazma girişiminde bulunulduğunda, dosya adı bir GUID tarafından otomatik olarak eklenir.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.
Oluşturucular
| TextWriterTraceListener() |
TextWriterTraceListenerÇıkış alıcısı olarak sınıfının yeni bir örneğini başlatır TextWriter .Initializes a new instance of the TextWriterTraceListener class with TextWriter as the output recipient. |
| TextWriterTraceListener(Stream) |
TextWriterTraceListenerHata ayıklama ve izleme çıkışının alıcısı olarak akışı kullanarak sınıfının yeni bir örneğini başlatır.Initializes a new instance of the TextWriterTraceListener class, using the stream as the recipient of the debugging and tracing output. |
| TextWriterTraceListener(Stream, String) |
TextWriterTraceListenerHata ayıklama ve izleme çıkışının alıcısı olarak akışı kullanarak, belirtilen ada sahip bir sınıfın yeni bir örneğini başlatır.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) |
TextWriterTraceListenerHata ayıklama ve izleme çıkışının alıcısı olarak dosyayı kullanarak sınıfının yeni bir örneğini başlatır.Initializes a new instance of the TextWriterTraceListener class, using the file as the recipient of the debugging and tracing output. |
| TextWriterTraceListener(String, String) |
TextWriterTraceListenerHata ayıklama ve izleme çıkışının alıcısı olarak dosyayı kullanarak, belirtilen ada sahip bir sınıfın yeni bir örneğini başlatır.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) |
TextWriterTraceListenerBelirtilen yazıcıyı izleme veya hata ayıklama çıkışının alıcısı olarak kullanarak sınıfının yeni bir örneğini başlatır.Initializes a new instance of the TextWriterTraceListener class using the specified writer as recipient of the tracing or debugging output. |
| TextWriterTraceListener(TextWriter, String) |
Belirtilen TextWriterTraceListener yazıcıyı izlemenin veya hata ayıklama çıkışının alıcısı olarak kullanarak, belirtilen ada sahip bir sınıfın yeni bir örneğini başlatır.Initializes a new instance of the TextWriterTraceListener class with the specified name, using the specified writer as recipient of the tracing or debugging output. |
Özellikler
| Attributes |
Uygulama yapılandırma dosyasında tanımlanan özel izleme dinleyicisi özniteliklerini alır.Gets the custom trace listener attributes defined in the application configuration file. (Devralındığı yer: TraceListener) |
| Filter |
İzleme dinleyicisi için izleme filtresini alır veya ayarlar.Gets or sets the trace filter for the trace listener. (Devralındığı yer: TraceListener) |
| IndentLevel |
Girinti düzeyini alır veya ayarlar.Gets or sets the indent level. (Devralındığı yer: TraceListener) |
| IndentSize |
Girintideki boşluk sayısını alır veya ayarlar.Gets or sets the number of spaces in an indent. (Devralındığı yer: TraceListener) |
| IsThreadSafe |
İzleme dinleyicisinin iş parçacığı açısından güvenli olup olmadığını gösteren bir değer alır.Gets a value indicating whether the trace listener is thread safe. (Devralındığı yer: TraceListener) |
| Name |
Bunun için bir ad alır veya ayarlar TraceListener .Gets or sets a name for this TraceListener. (Devralındığı yer: TraceListener) |
| NeedIndent |
Çıktının girintisini gösterip göstermeyeceğinizi gösteren bir değer alır veya ayarlar.Gets or sets a value indicating whether to indent the output. (Devralındığı yer: TraceListener) |
| TraceOutputOptions |
İzleme çıktısı seçeneklerini alır veya ayarlar.Gets or sets the trace output options. (Devralındığı yer: TraceListener) |
| Writer |
İzleme veya hata ayıklama çıkışını alan metin yazıcısını alır veya ayarlar.Gets or sets the text writer that receives the tracing or debugging output. |
Yöntemler
| Close() |
WriterArtık izleme veya hata ayıklama çıktısı alması için öğesini kapatır.Closes the Writer so that it no longer receives tracing or debugging output. |
| Close() |
Türetilmiş bir sınıfta geçersiz kılındığında, çıkış akışını, artık izleme veya hata ayıklama çıktısı alması için kapatır.When overridden in a derived class, closes the output stream so it no longer receives tracing or debugging output. (Devralındığı yer: TraceListener) |
| CreateObjRef(Type) |
Uzak bir nesneyle iletişim kurmak için kullanılan bir ara sunucu oluşturmak için gereken tüm bilgileri içeren bir nesne oluşturur.Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object. (Devralındığı yer: MarshalByRefObject) |
| Dispose() |
TraceListener tarafından kullanılan tüm kaynakları serbest bırakır.Releases all resources used by the TraceListener. (Devralındığı yer: TraceListener) |
| Dispose(Boolean) |
Bu nesneyi atar TextWriterTraceListener .Disposes this TextWriterTraceListener object. |
| Equals(Object) |
Belirtilen nesnenin geçerli nesneye eşit olup olmadığını belirler.Determines whether the specified object is equal to the current object. (Devralındığı yer: Object) |
| Fail(String) |
Sınıfı uygularken oluşturduğunuz dinleyiciye bir hata iletisi gönderir TraceListener .Emits an error message to the listener you create when you implement the TraceListener class. (Devralındığı yer: TraceListener) |
| Fail(String, String) |
Sınıfı uyguladığınızda oluşturduğunuz dinleyiciye bir hata iletisi ve ayrıntılı bir hata iletisi gönderir TraceListener .Emits an error message and a detailed error message to the listener you create when you implement the TraceListener class. (Devralındığı yer: TraceListener) |
| Flush() |
İçin çıkış arabelleğini temizler Writer .Flushes the output buffer for the Writer. |
| GetHashCode() |
Varsayılan karma işlevi olarak işlev görür.Serves as the default hash function. (Devralındığı yer: Object) |
| GetLifetimeService() |
Kullanımdan kalktı.
Bu örnek için ömür ilkesini denetleyen geçerli ömür hizmeti nesnesini alır.Retrieves the current lifetime service object that controls the lifetime policy for this instance. (Devralındığı yer: MarshalByRefObject) |
| GetSupportedAttributes() |
İzleme dinleyicisi tarafından desteklenen özel öznitelikleri alır.Gets the custom attributes supported by the trace listener. (Devralındığı yer: TraceListener) |
| GetType() |
TypeGeçerli örneği alır.Gets the Type of the current instance. (Devralındığı yer: Object) |
| InitializeLifetimeService() |
Kullanımdan kalktı.
Bu örnek için ömür ilkesini denetlemek üzere bir ömür hizmeti nesnesi alır.Obtains a lifetime service object to control the lifetime policy for this instance. (Devralındığı yer: MarshalByRefObject) |
| MemberwiseClone() |
Geçerli bir basit kopyasını oluşturur Object .Creates a shallow copy of the current Object. (Devralındığı yer: Object) |
| MemberwiseClone(Boolean) |
Geçerli nesnenin basit bir kopyasını oluşturur MarshalByRefObject .Creates a shallow copy of the current MarshalByRefObject object. (Devralındığı yer: MarshalByRefObject) |
| ToString() |
Geçerli nesneyi temsil eden dizeyi döndürür.Returns a string that represents the current object. (Devralındığı yer: Object) |
| TraceData(TraceEventCache, String, TraceEventType, Int32, Object) |
İzleyici bilgilerini, veri nesnesini ve olay bilgilerini dinleyiciye özgü çıktıya yazar.Writes trace information, a data object and event information to the listener specific output. (Devralındığı yer: TraceListener) |
| TraceData(TraceEventCache, String, TraceEventType, Int32, Object[]) |
İzleyici bilgilerini, veri nesneleri dizisini ve olay bilgilerini dinleyiciye özel çıktıya yazar.Writes trace information, an array of data objects and event information to the listener specific output. (Devralındığı yer: TraceListener) |
| TraceEvent(TraceEventCache, String, TraceEventType, Int32) |
İzleyici ve olay bilgilerini dinleyiciye özgü çıktıya yazar.Writes trace and event information to the listener specific output. (Devralındığı yer: TraceListener) |
| TraceEvent(TraceEventCache, String, TraceEventType, Int32, String) |
İzleyici bilgilerini, bir iletiyi ve olay bilgilerini dinleyiciye özgü çıktıya yazar.Writes trace information, a message, and event information to the listener specific output. (Devralındığı yer: TraceListener) |
| TraceEvent(TraceEventCache, String, TraceEventType, Int32, String, Object[]) |
İzleyici bilgilerini, bir nesne ve olay bilgilerini, dinleyiciye özgü çıktıya yazar.Writes trace information, a formatted array of objects and event information to the listener specific output. (Devralındığı yer: TraceListener) |
| TraceTransfer(TraceEventCache, String, Int32, String, Guid) |
İzleyici bilgilerini, bir iletiyi, ilgili etkinlik kimliğini ve olay bilgilerini dinleyiciye özgü çıktıya yazar.Writes trace information, a message, a related activity identity and event information to the listener specific output. (Devralındığı yer: TraceListener) |
| Write(Object) |
Nesne yönteminin değerini, ToString() sınıfı uyguladığınızda oluşturduğunuz dinleyiciye yazar TraceListener .Writes the value of the object's ToString() method to the listener you create when you implement the TraceListener class. (Devralındığı yer: TraceListener) |
| Write(Object, String) |
ToString()Sınıfı uygularken oluşturduğunuz dinleyiciye bir kategori adı ve nesne yöntemi değeri yazar TraceListener .Writes a category name and the value of the object's ToString() method to the listener you create when you implement the TraceListener class. (Devralındığı yer: TraceListener) |
| Write(String) |
Bu örneğe bir ileti yazar Writer .Writes a message to this instance's Writer. |
| Write(String, String) |
Sınıfı uygularken oluşturduğunuz dinleyiciye bir kategori adı ve ileti yazar TraceListener .Writes a category name and a message to the listener you create when you implement the TraceListener class. (Devralındığı yer: TraceListener) |
| WriteIndent() |
Bu sınıfı uygularken oluşturduğunuz dinleyiciye girinti yazar ve NeedIndent özelliğini olarak sıfırlar |
| WriteLine(Object) |
Nesnenin ToString() yönteminin değerini, sınıfı uyguladığınızda oluşturduğunuz dinleyiciye yazar ve TraceListener ardından bir satır Sonlandırıcı gelir.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. (Devralındığı yer: TraceListener) |
| WriteLine(Object, String) |
Bir kategori adı ve nesnenin ToString() yönteminin değerini, sınıfı uyguladığınızda oluşturduğunuz dinleyiciye TraceListener , ardından bir satır Sonlandırıcı ile yazar.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. (Devralındığı yer: TraceListener) |
| WriteLine(String) |
Bu örneğe bir ileti yazar Writer ve ardından satır Sonlandırıcı izler.Writes a message to this instance's Writer followed by a line terminator. Varsayılan satır Sonlandırıcı, ardından bir satır besleme (\r\n) tarafından izlenen bir satır sonu olur.The default line terminator is a carriage return followed by a line feed (\r\n). |
| WriteLine(String, String) |
Sınıfı uyguladığınızda oluşturduğunuz dinleyiciye bir kategori adı ve ileti yazar ve TraceListener ardından bir satır Sonlandırıcı gelir.Writes a category name and a message to the listener you create when you implement the TraceListener class, followed by a line terminator. (Devralındığı yer: TraceListener) |