473,395 Members | 1,488 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Is Trace.Close() really needed?

I'm building a Windows service that writes log messages via TraceListeners.
I assume Trace.Close() is useful for garbage collection, but I'm not sure
where to call it in the Windows service. Any thoughts?
Oct 3 '06 #1
2 2502
Marc,

If you want to flush the contents of the trace to the file, then yes,
you do. And no, Close is not useful for garbage collection, as the
instances are not released.

In your windows service, you should probably call it when the service
shuts down, and when it pauses.

If you call Close, and you initialized the text file trace listener with
a filename, then it will reopen the file and write to it when another call
to Trace is made. If you pass a stream, then the stream is closed, and it
doesn't write to the stream again.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Marc" <Ma**@discussions.microsoft.comwrote in message
news:F4**********************************@microsof t.com...
I'm building a Windows service that writes log messages via
TraceListeners.
I assume Trace.Close() is useful for garbage collection, but I'm not sure
where to call it in the Windows service. Any thoughts?

Oct 3 '06 #2
Thank you. I appreciate your insight. I will definitely use the file name
approach rather than the stream approach since it sounds more flexible.

"Nicholas Paldino [.NET/C# MVP]" wrote:
Marc,

If you want to flush the contents of the trace to the file, then yes,
you do. And no, Close is not useful for garbage collection, as the
instances are not released.

In your windows service, you should probably call it when the service
shuts down, and when it pauses.

If you call Close, and you initialized the text file trace listener with
a filename, then it will reopen the file and write to it when another call
to Trace is made. If you pass a stream, then the stream is closed, and it
doesn't write to the stream again.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Marc" <Ma**@discussions.microsoft.comwrote in message
news:F4**********************************@microsof t.com...
I'm building a Windows service that writes log messages via
TraceListeners.
I assume Trace.Close() is useful for garbage collection, but I'm not sure
where to call it in the Windows service. Any thoughts?


Oct 3 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Serge calderara | last post by:
============ RESEND ================ Dear all, I have implementing some tracing function in my applicatrion to store log information to file and event logger. I have actually a problem to...
2
by: Wilfried Hoermann | last post by:
Presumably a trivial question... I want to write trace information from a web service to a log file using the Trace Class. Is this possible without closing and opening the Trace in every single...
0
by: martin | last post by:
Hi, I have created an asp.net application as a project, and also another project that is just a class library. My asp.net application calls a function in the class library. I am attempting to...
2
by: Tiësto | last post by:
Should I always check if Trace is enabled before attempting to use Trace.Write or Trace.Warn? will it throw an exception if I don't? will It make thing slower if I write entries in the trace when I...
0
by: Taylor H. Maxwell | last post by:
I am trying to build a generic system for tracking unhandled errors which will place such errors into a log file and the event log. The code is listed below. When I try to run this code below, I...
35
by: Eric Sabine | last post by:
In my Finally block, I was using cn.close (where cn is an ADO.NET connection object, SQLConnection to be exact) and then I came across the following in some microsoft code. If Not cn Is Nothing...
2
by: Jason L James | last post by:
Hi all, can anyone help me with some tracing I am trying to do in my application. I have a configuration file containing the XML as detailed below: <?xml version="1.0" encoding="utf-8" ?>...
45
by: Arno R | last post by:
Hi all, I am about to distribute an A97-runtime app. which will be used on a LAN by approx. 30 users. The network is pretty good, but there are a few managers who have wireless laptops... Of...
6
by: Zytan | last post by:
According to http://www.15seconds.com/issue/020910.htm I am doing this in the c'tor of a 'logfile' class: objStream = new System.IO.FileStream(logFilename, System.IO.FileMode.OpenOrCreate);...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.