Search:
Namespaces
Discussions
.NET v1.1
Feedback
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
Ad
MBR BootFX
Best-of-breed application framework for .NET projects, developed by Matthew Baxter-Reynolds and MBR IT
Copyright © Matthew Baxter-Reynolds 2001-2008. '.NET 247 Software Development Services' is a trading style of MBR IT Solutions Ltd.
Contact Us
-
Terms of Use
-
Privacy Policy
-
www.dotnet247.com