|
Exemple 16-18 extrait du chapitre Bibliothèques de classes
Exemple 16-17< > Exemple 16-19
Cet exemple peut être compilé avec la ligne de commande: csc.exe /target:exe Exemple_16_18.cs Erreurs: 0 Avertissements: 0 Remarque:
Exemple_16_18.cs
using System.Diagnostics;
class Program {
static TraceSource trace1;
const int IndentSize = 3;
static string IndentLevel { get{
StackTrace stackTrace = new StackTrace();
return new string( ' ',(stackTrace.FrameCount - 2)* IndentSize);
}
}
static void Main() {
trace1 = new TraceSource("Trace1");
trace1.Listeners.Add(new ConsoleTraceListener());
trace1.Switch.Level = SourceLevels.All;
trace1.TraceInformation( IndentLevel + "Begin Main()");
fct(2);
trace1.TraceInformation( IndentLevel + "End Main()");
}
static void fct(int i) {
trace1.TraceInformation( IndentLevel +
"Begin fct(" + i.ToString() + ")" );
if (i > 0)
fct(i-1);
trace1.TraceInformation( IndentLevel +
"End fct(" + i.ToString() + ")" );
}
}
Copyright Patrick Smacchia 2006 2007
|