473,794 Members | 2,765 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help please with Trace Class!!

4 New Member
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 1900
Plater
7,872 Recognized Expert Expert
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 Recognized Expert New Member
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 TextWriterTrace Listener, 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.Trunca te 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 Recognized Expert New Member
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
1514
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 descriptor. But it crashes. I've tracked the crash down to a call to PyObject_GenericGetAttr. When I sub-class my class the tp_dictoffset comes out as -4 which quoting from PyObject_GenericGetAttr: """
1
1491
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 have Object Created #temp1, Object Created #temp2, Object Created #temp3. How can I fix the trace so it does not report any objects that get created in the tempdb. Any help will be appreciated.
2
2044
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" facility. I am to get rid of them and replace them with exceptions. I need to create a "linkedListException" class that's declared and implemented in my "linkedListType" class. This class needs to inherit from the base "exception" class and return...
0
853
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. The class sent to us can not be compiled as managed code so I have built a managed wrapper class... here is the general code #using <mscorlib.dll> #pragma once
3
1943
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 are over 100 in total). I would to have them set up the same as i have "form_id" below, but im not sure what the syntax to do it is (without actually typing each one). ' declare form_id private form_id
2
1673
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 "pipelines" you can make with command-line programs. So, I wrote a module called iterwrap.py. You can download it from here: http://home.blarg.net/~steveha/iterwrap.tar.gz
1
5758
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 security number, position, and hourly wages. Define the instance data for this class Answer: employeeName=name; employeePosition=position; hourlyWage=wage;
11
4060
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”. Make the class implement the Comparable interface. Include a toString method. Write a driver program to demonstrate your work. Instantiate several objects of the Student class. Call your methods several times to show that class is ordered. ...
4
2355
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 to create the table was that there is not Cell Click event. So I did some looking and asked around and got this C# (see below) version of a class that someone built to create a clickable cell.
0
9671
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10433
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10161
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10000
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9035
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6777
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5560
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4112
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2919
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.