|
Cet article a fait l'objet d'une traduction automatique. Déplacez votre pointeur sur les phrases de l'article pour voir la version originale de ce texte. Informations supplémentaires.
|
Traduction
Source
|
ConsoleTraceListener, classe
System.MarshalByRefObject
System.Diagnostics.TraceListener
System.Diagnostics.TextWriterTraceListener
System.Diagnostics.ConsoleTraceListener
Espace de noms : System.Diagnostics
Assembly : System (dans System.dll)
Le type ConsoleTraceListener expose les membres suivants.
| Nom | Description | |
|---|---|---|
![]() | ConsoleTraceListener() | |
![]() | ConsoleTraceListener(Boolean) |
| Nom | Description | |
|---|---|---|
![]() | Attributes | |
![]() | Filter | |
![]() | IndentLevel | |
![]() | IndentSize | |
![]() | IsThreadSafe | |
![]() | Name | |
![]() | NeedIndent | |
![]() | TraceOutputOptions | |
![]() | Writer |
| Nom | Description | |
|---|---|---|
![]() | Close | |
![]() | CreateObjRef | |
![]() | Dispose() | |
![]() | Dispose(Boolean) | Infrastructure. |
![]() | Equals(Object) | |
![]() | Fail(String) | |
![]() | Fail(String, String) | |
![]() | Finalize | |
![]() | Flush | |
![]() | GetHashCode | |
![]() | GetLifetimeService | |
![]() | GetSupportedAttributes | |
![]() | GetType | |
![]() | InitializeLifetimeService | |
![]() | MemberwiseClone() | |
![]() | MemberwiseClone(Boolean) | |
![]() | ToString | |
![]() | TraceData(TraceEventCache, String, TraceEventType, Int32, Object) | |
![]() | TraceData(TraceEventCache, String, TraceEventType, Int32, Object[]) | |
![]() | TraceEvent(TraceEventCache, String, TraceEventType, Int32) | |
![]() | TraceEvent(TraceEventCache, String, TraceEventType, Int32, String) | |
![]() | TraceEvent(TraceEventCache, String, TraceEventType, Int32, String, Object[]) | |
![]() | TraceTransfer | |
![]() | Write(Object) | |
![]() | Write(String) | |
![]() | Write(Object, String) | |
![]() | Write(String, String) | |
![]() | WriteIndent | |
![]() | WriteLine(Object) | |
![]() | WriteLine(String) | |
![]() | WriteLine(Object, String) | |
![]() | WriteLine(String, String) |
Remarque |
|---|
Remarque |
|---|
Pour activer le débogage en C#, ajoutez l'indicateur /d:DEBUG à la ligne de commande du compilateur lors de la compilation du code, ou ajoutez #define DEBUG au début du fichier. En Visual Basic, ajoutez l'indicateur /d:DEBUG=True à la ligne de commande du compilateur. Pour activer le traçage en C#, ajoutez l'indicateur /d:TRACE à la ligne de commande du compilateur lors de la compilation du code ou ajoutez #define TRACE au début du fichier. En Visual Basic, ajoutez l'indicateur /d:TRACE=True à la ligne de commande du compilateur.
<configuration>
<system.diagnostics>
<trace autoflush="false" indentsize="4">
<listeners>
<add name="configConsoleListener"
type="System.Diagnostics.ConsoleTraceListener" />
</listeners>
</trace>
</system.diagnostics>
</configuration>
Remarque |
|---|
L'attribut HostProtectionAttribute appliqué à ce type ou membre a la valeur de propriété Resources suivante : Synchronization. HostProtectionAttribute n'affecte pas les applications bureautiques (qui sont généralement démarrées en double-cliquant sur une icône, en tapant une commande ou en entrant une URL dans un navigateur). Pour plus d'informations, consultez la classe HostProtectionAttribute ou Attributs de programmation et de protection des hôtes SQL Server. |
// Define the TRACE directive, which enables trace output to the // Trace.Listeners collection. Typically, this directive is defined // as a compilation argument. #define TRACE using System; using System.Diagnostics; public class ConsoleTraceSample { // Define a simple method to write details about the current executing // environment to the trace listener collection. public static void WriteEnvironmentInfoToTrace() { string methodName = "WriteEnvironmentInfoToTrace"; Trace.Indent(); Trace.WriteLine(DateTime.Now.ToString() + " - Start of " + methodName); Trace.Indent(); // Write details on the executing environment to the trace output. Trace.WriteLine("Operating system: " + System.Environment.OSVersion.ToString()); Trace.WriteLine("Computer name: " + System.Environment.MachineName); Trace.WriteLine("User name: " + System.Environment.UserName); Trace.WriteLine("CLR runtime version: " + System.Environment.Version.ToString()); Trace.WriteLine("Command line: " + System.Environment.CommandLine); // Enumerate the trace listener collection and // display details about each configured trace listener. Trace.WriteLine("Number of configured trace listeners = " + Trace.Listeners.Count.ToString()); foreach (TraceListener tl in Trace.Listeners) { Trace.WriteLine("Trace listener name = " + tl.Name); Trace.WriteLine(" type = " + tl.GetType().ToString()); } Trace.Unindent(); Trace.WriteLine(DateTime.Now.ToString() + " - End of " + methodName); Trace.Unindent(); } // Define the main entry point of this class. // The main method adds a console trace listener to the collection // of configured trace listeners, then writes details on the current // executing environment. public static void Main(string[] CmdArgs) { // Write a trace message to all configured trace listeners. Trace.WriteLine(DateTime.Now.ToString()+" - Start of Main"); // Define a trace listener to direct trace output from this method // to the console. ConsoleTraceListener consoleTracer; // Check the command line arguments to determine which // console stream should be used for trace output. if ((CmdArgs.Length>0)&&(CmdArgs[0].ToString().ToLower().Equals("/stderr"))) // Initialize the console trace listener to write // trace output to the standard error stream. { consoleTracer = new ConsoleTraceListener(true); } else { // Initialize the console trace listener to write // trace output to the standard output stream. consoleTracer = new ConsoleTraceListener(); } // Set the name of the trace listener, which helps identify this // particular instance within the trace listener collection. consoleTracer.Name = "mainConsoleTracer"; // Write the initial trace message to the console trace listener. consoleTracer.WriteLine(DateTime.Now.ToString()+" ["+consoleTracer.Name+"] - Starting output to trace listener."); // Add the new console trace listener to // the collection of trace listeners. Trace.Listeners.Add(consoleTracer); // Call a local method, which writes information about the current // execution environment to the configured trace listeners. WriteEnvironmentInfoToTrace(); // Write the final trace message to the console trace listener. consoleTracer.WriteLine(DateTime.Now.ToString()+" ["+consoleTracer.Name+"] - Ending output to trace listener."); // Flush any pending trace messages, remove the // console trace listener from the collection, // and close the console trace listener. Trace.Flush(); Trace.Listeners.Remove(consoleTracer); consoleTracer.Close(); // Write a final trace message to all trace listeners. Trace.WriteLine(DateTime.Now.ToString()+" - End of Main"); // Close all other configured trace listeners. Trace.Close(); } }
Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (rôle principal du serveur non pris en charge), Windows Server 2008 R2 (rôle principal du serveur pris en charge avec SP1 ou version ultérieure ; Itanium non pris en charge)
Le .NET Framework ne prend pas en charge toutes les versions de chaque plateforme. Pour obtenir la liste des versions prises en charge, consultez Configuration requise du .NET Framework.
