Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / February 2008

Tip: Looking for answers? Try searching our database.

Initializing a TraceListener Writer to a stream in app.config.

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
michael sorens - 18 Feb 2008 23:36 GMT
I would like to be able to define a TraceListener in my app.config file whose
Writer is a stream. I understand how to do this in code, but I have not been
successful in getting it to work with the app.config file. I had hoped that I
could just omit the initializeData attribute and then assign a Writer in
code, which would suit my purpose. But it seems that any attempt to access
the TraceSource configuration generates a ConfigurationErrorsException. That
is, if I attempt to assign a Writer like this:
        ((TextWriterTraceListener)mySource.Listeners["ExperimentalListener"]).Writer = strWriter = new StringWriter();

I get the aforementioned exception.

Is there a way to initialize the Writer to a StringWriter within the
app.config file itself?

[My environment: .NET 2.0, VS2005]
Steven Cheng - 19 Feb 2008 10:38 GMT
Hi Michael,

As for the TextTraceListener, based on my research, the undelying Writer it
used is hard coded as "StreamWriter" and use the "initliazeData" to get the
log file path. Therefore, I'm afraid this class is not supposed to let you
change different kind of underlying writer.  For such scenario,
implementing a custom Tracelistener should be the reasonable approach:

#Implementing a Custom TraceListener
http://www.codeguru.com/vb/gen/vb_misc/debuggingandtracing/article.php/c5611
/

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
>From: =?Utf-8?B?bWljaGFlbCBzb3JlbnM=?= <m_j_sorens@newsgroup.nospam>
>Subject: Initializing a TraceListener Writer to a stream in app.config.
>Date: Mon, 18 Feb 2008 15:36:00 -0800

>I would like to be able to define a TraceListener in my app.config file whose
>Writer is a stream. I understand how to do this in code, but I have not been
[quoted text clipped - 3 lines]
>the TraceSource configuration generates a ConfigurationErrorsException. That
>is, if I attempt to assign a Writer like this:
       
((TextWriterTraceListener)mySource.Listeners["ExperimentalListener"]).Writer
= strWriter = new StringWriter();

>I get the aforementioned exception.
>
>Is there a way to initialize the Writer to a StringWriter within the
>app.config file itself?
>
>[My environment: .NET 2.0, VS2005]
michael sorens - 19 Feb 2008 19:27 GMT
I thought that might be the case. I found, however, that if I specify a dummy
filename in the app.config, then during my program initialization I could
re-assign the Writer to be a StringWriter.
Steven Cheng - 20 Feb 2008 01:31 GMT
Thanks for your reply Michael,

Sounds like a workable trick. Anyway, glad that you've got it working.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
>From: =?Utf-8?B?bWljaGFlbCBzb3JlbnM=?= <m_j_sorens@newsgroup.nospam>
>References:  <0BB6E876-46C2-435F-8098-BA8DD51F370B@microsoft.com>
<n3yyTOucIHA.5204@TK2MSFTNGHUB02.phx.gbl>
>Subject: RE: Initializing a TraceListener Writer to a stream in app.config.
>Date: Tue, 19 Feb 2008 11:27:02 -0800

>I thought that might be the case. I found, however, that if I specify a dummy
>filename in the app.config, then during my program initialization I could
>re-assign the Writer to be a StringWriter.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.