> Instead of using the DefaultTraceListener you can write your own Listener
> class (derived from TraceListener) to output the message to a file, eventlog
> (e-mail, WWW, RSS, SMS or whatever way you want to get notified).
I better understand what you were saying now, from our most recent
thread. Although to be critical, I wouldn't need my own TraceListener
class to log to a file, as this article you gave me shows:
http://www.15seconds.com/issue/020910.htm
I am not sure why. Oh, because a TextWriterTraceListener already
exists (the class I would have made). But, yes, for something else,
other than writing to a file, I'd need to make my own.
> To give a clue, here is a basic sample using the StackTrace class (has to be
> improved):
>
> public class MyListener : TraceListener
> {
> public override void Write(string message){} // work this out
> public override void WriteLine(string message){} // work this out
>
> public override void Fail(string message)
> {
> HandleFail(message, string.Empty);
> }
>
> public override void Fail(string message, string detailMessage)
> {
> HandleFail(message, detailMessage);
> }
>
> private void HandleFail(string message, string detailMessage)
> {
> StackTrace st = new StackTrace(true);
> Console.WriteLine("{0} {1}\r\n{2}", message, detailMessage, new
> StackTrace(true).ToString());
>
> }
>
> }
>
> public static void Main()
> {
> Trace.Listeners.Add(new MyListener());
> Debug.Assert(false, "Oops"); // force assertion
> Trace.Flush();
> }
>
> Regards,
> Anne
Thanks Anne, this is a great help!
Zytan