trace listener - log file size & reset log file content

B

Bandu

Hi,

I'm trying to write trace out using TextWriterTraceListener. It work
fine. But I would like to do the following 2 tasks but I can't find
any way to do it.

- Limit maximum log file size
- Refresh log file content everytime program start.

thank you very much,

Bandu
 
P

Peter Duniho

Bandu said:
Hi,

I'm trying to write trace out using TextWriterTraceListener. It work
fine. But I would like to do the following 2 tasks but I can't find
any way to do it.

- Limit maximum log file size
- Refresh log file content everytime program start.

To accomplish the first, you'll need to create your own TraceListener
sub-class (perhaps inheriting TextWriter, depending on specifics),
monitoring the output log file size and restricting the size as
appropriate to your needs.

I don't really understand the second, not without a concise-but-complete
code example from you demonstrating exactly what you're doing. Seems to
me that if you just delete the previous output file when your program
starts, that would accomplish what you're asking for.

Pete
 
R

Roger Frost

Greetings,

I believe what you're referring to is known as a "rolling" log. Where the
top (most recent) N number of entries are maintained between program
executions, and older entries are dropped in the interest of file size.

If this is the case, you can find some helpful examples and open source
solutions here:
http://csharp-source.net/open-source/logging

Google will turn up more possibilities, there are a lot of these types of
libraries available for .Net. I've also build my own before to address my
particular needs, it's not too difficult.

Hope this helps,
 
B

Bandu

To accomplish the first, you'll need to create your own TraceListener
sub-class (perhaps inheriting TextWriter, depending on specifics),
monitoring the output log file size and restricting the size as
appropriate to your needs.

I don't really understand the second, not without a concise-but-complete
code example from you demonstrating exactly what you're doing.  Seems to
me that if you just delete the previous output file when your program
starts, that would accomplish what you're asking for.

Pete

thanks Pete.
 
B

Bandu

Greetings,

I believe what you're referring to is known as a "rolling" log.  Where the
top (most recent) N number of entries are maintained between program
executions, and older entries are dropped in the interest of file size.

If this is the case, you can find some helpful examples and open source
solutions here:http://csharp-source.net/open-source/logging

Google will turn up more possibilities, there are a lot of these types of
libraries available for .Net.  I've also build my own before to addressmy
particular needs, it's not too difficult.

Hope this helps,
--
Roger Frost
"It's all about finding the correct solution. The solution exists,
this is just software :) There are no non-solutions." -Anthony Nystrom










- Show quoted text -

thanks Roger.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top