473,398 Members | 2,403 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,398 software developers and data experts.

Help please with Trace Class!!

Hello there,

I am working on an service that uses Trace.writeline(....) to log its activities. My question is, is there any way to clear this log while the application is still running. My service runs for a long time (days, if any bad code doesnt crash it) and as the time goes by the log is growin huge in size. So what I am trying to do is check for the log files' size and clear it or delete it (when it exceeds a size limit) while the service is still running. Is this possible? If not any suggestions or work arounds are welcome.
Dec 31 '08 #1
3 1885
Plater
7,872 Expert 4TB
I went looking on msdn, and their wording suggests that you yourself have to write the actual "to disk" section of the logging, so whereever you do that, simple check the logfile size?
According to msdn it works just like Debug, just a uniform way to report messages.

Edit: on 2nd look, there is a default listener that you can examine i think.
Check Trace.Listeners[0].LogFileName for the filename maybe?
Dec 31 '08 #2
mldisibio
190 Expert 100+
That is actually an interesting scenario. Just to let you know you are not alone, SQL Server has the same issue. If you do not manually backup the log or schedule it for periodic backups, it grows until it reaches either a pre-set limit or runs out of disk space. Either way, it simply stops and throws an error.

When you set up a TextWriterTraceListener, there are different options for creating the file. If you choose the most explicit option of actually creating the FileStream, you can set the access mode to shared read and write.
I say this because my suggestion would be to have a separate thread which periodically fires and
- checks the trace file size
- if over limit, backs it up or zips it
- truncates the existing file: FileMode.Truncate will do this...but I am not sure if it will conflict with the TraceListener's handle to the open stream.

If you can get the shared access part to work (so that both your TraceListener and the Archiving Thread can read and write to the target file) this should allow you to clean up the file while your containing application is still running. You might have to stop the TraceListener, truncate the file, then restart the TraceListener.

These are just suggestions. I haven't actually implemented a clean-up of a long-running log yet. If someone else has, hopefully they will post a clearer solution.
Dec 31 '08 #3
vekipeki
229 Expert 100+
I don't think you will not be able to change your file while it is being used by a TraceListener.

You will probably have to remove it from Trace.Listeners, close the Listener's underlying stream, do whatever you want to do with the file, and then reopen the stream and add your Listener to Trace.Listeners.
Jan 2 '09 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Giles Brown | last post by:
Hello folks, I'm tryin to write an extension class in C (been a while since I wrote some C :-). I want the class to be inheritable from Python. I've put the magic incantations into the type...
1
by: Alee Ali | last post by:
Hello: I am working with SQL Server 2000. I have a stored procedure that creates 3 temporary tables (#temp1, #temp2, #temp3). When I view the trace of the stored procedure I see entries that...
2
by: dinks | last post by:
Hi, I'm new to C++ and have been assigned a task which i dont completely understand. Any help would be greately appreciated. Here is the problem: The class "linkedListType" use the "assert"...
0
by: Rick | last post by:
We have an class sent to us by a vendor in a .h file. This class controls access to a subsystem for gathering data. Currently we are using C++ 6.0 to access this class. Now we want to move to .net....
3
by: Dan | last post by:
Is it possible to dynamically create and populate properties? Below is my class. I would like to define properties for each of the items in my two arrays without actually defining each one. (There...
2
by: Steve R. Hastings | last post by:
While studying iterators and generator expressions, I started wishing I had some tools for processing the values. I wanted to be able to chain together a set of functions, sort of like the...
1
by: xxbabysue123xx | last post by:
here are a couple of questions i tried doing but not sure if they are correct. if anyone could please help with with them that would be great.. thanks An Employee will have a name, social...
11
by: xxbabysue123xx | last post by:
Heres the problem: Create a class Student with instance data name, studentNumber, class (where class is a String containing one of the following: “Freshman”, “Sophomore”, “Junior”, “Senior”. ...
4
by: Ty | last post by:
Hello all, I am creating a website in VS 2008 VB.net. On one of my pages I am using the Table control to make a type of calendar a IN/OUT board. The problem I found after I wrote all the code...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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.