.NETGURU
Writing EventLogs to Text File
Messages   Related Types
This message was discovered on ASPFriends.com 'ngfx-io' list.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.

dexter
-- Copied from [aspngfreeforall] to [ngfx-io] by Tim Musschoot <Click here to reveal e-mail address> --

I've written a Windows Service using the .NET framework. I want to write
EventLogs to a text file, rather than to one of the EventLogs themselves.
I'm aware that this is something to do with using the
TextWriterTraceListener class which redirects output to an instance of the
TextWriter class or to anything that is a Stream class.

But I'm not sure how can this be done.
Any pointers?

Thanks

Reply to this message...
 
    
Mitch Denny (VIP)
Dexter,

One of the easiest ways is to specify a trace listner in
the configuration files like this:

    <configuration>
        <system.diagnostics>
            <trace autoflush="true" indentsize="0">
                <listeners>
                    <add
                        name="MyListener"
    
type="System.Diagnostics.TextWriterTraceListener,System"
    
initializeData="MyListener.log"
                        />
                </listeners>
            </trace>
        </system.diagnostics>
    </configuration>

This gives you some runtime flexibility because if
you wanted you could then flip it over to record
in the event log (or both). The snippet above is
straight out of the SDK documentation for the <trace />
configuration element.

Once you have done this all you have to do is make
calls like this in your code:

    Trace.WriteLine("Doing something especially complicated here.");

Hope this helps.

----------------------------------------
- Mitch Denny
- Click here to reveal e-mail address
- +61 (414) 610-141
-

-----Original Message-----
From: dexter [mailto:Click here to reveal e-mail address]
Sent: Wednesday, 26 June 2002 00:14
To: ngfx-io
Subject: [ngfx-io] Writing EventLogs to Text File

-- Copied from [aspngfreeforall] to [ngfx-io] by Tim Musschoot
<Click here to reveal e-mail address> --

I've written a Windows Service using the .NET framework. I want to write
EventLogs to a text file, rather than to one of the EventLogs
themselves. I'm aware that this is something to do with using the
TextWriterTraceListener class which redirects output to an instance of
the TextWriter class or to anything that is a Stream class.

But I'm not sure how can this be done.
Any pointers?

Thanks

| [ngfx-io] member Click here to reveal e-mail address = YOUR ID
| http://www.aspfriends.com/aspfriends/ngfx-io.asp = JOIN/QUIT

Reply to this message...
 
    
Paul D. Murphy
A better approach to solving the problem is to centralize this code into
a component that you can get re-use out of. Microsoft has an exception
management application block on MSDN Downloads that provides an
infrastructure for publishing exception information. The default
publisher is to the Windows event log, but there is an interface defined
to publishing out to other sources (an example of publishing to an XML
document is included in the docs). This app block from MS is an
'exceptional' way of dealing with exceptions.

http://download.microsoft.com/download/visualstudionet/emabref/rtm/nt5/e
n-us/ExceptionManagementApplicationBlock.msi

Paul

    Paul D. Murphy
    Click here to reveal e-mail address
    "Teamwork is a lot of people doing what I say."

-----Original Message-----
From: dexter [mailto:Click here to reveal e-mail address]=20
Sent: Tuesday, June 25, 2002 10:14 AM
To: ngfx-io
Subject: [ngfx-io] Writing EventLogs to Text File

-- Copied from [aspngfreeforall] to [ngfx-io] by Tim Musschoot
<Click here to reveal e-mail address> --

I've written a Windows Service using the .NET framework. I want to write
EventLogs to a text file, rather than to one of the EventLogs
themselves.
I'm aware that this is something to do with using the
TextWriterTraceListener class which redirects output to an instance of
the
TextWriter class or to anything that is a Stream class.

But I'm not sure how can this be done.
Any pointers?

Thanks

| [ngfx-io] member Click here to reveal e-mail address =3D YOUR ID
| http://www.aspfriends.com/aspfriends/ngfx-io.asp =3D JOIN/QUIT

Reply to this message...
 
 
System.Diagnostics.TextWriterTraceListener
System.Diagnostics.Trace
System.IO.TextWriter




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification