[C#] Comment implémenter System.Diagnostics.Trace ?
Salut à toutes et à tous !
Je veux créer un fichier journal de mon application.
Dans le fichier App.config, j'ai mis
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.diagnostics>
<trace autoflush="false" indentsize="4">
<listeners>
<add name="myListener"
type="System.Diagnostics.TextWriterTraceListener"
initializeData="c:\myListener.log" />
<remove type="System.Diagnostics.DefaultTraceListener"/>
</listeners>
</trace>
</system.diagnostics>
</configuration> |
(exemple de MSDN).
Puis, dans mon appli winform, j'ai mis pour test
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
|
#define TRACE
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data ;
using System.Diagnostics ;
using System.Configuration ;
...
[STAThread]
static void Main()
{
System.Diagnostics.Debug.WriteLine("La trace contient " +
Trace.Listeners.Count + " listener(s).") ;
foreach(TraceListener tl in Trace.Listeners)
System.Diagnostics.Debug.WriteLine("\t" + tl.Name) ;
Trace.WriteLine("Démarrage de l'application") ;
Application.Run(new FenetrePrincipale()) ;
} |
Mais rien ne s'inscrit dans mon fichier log...
Citation:
Envoyé par Sortie
La trace contient 2 listener(s).
Default
myListener
Démarrage de l'application
Je ne comprends par pourquoi le TraceListener Default existe toujours étant donné le paramètres du fichier de config.
Je ne comprends pas non plus pourquoi rien ne s'affiche dans mon fichier log.
Est-ce que quelqu'un voit où se situe mon erreur :?: