C# log component

  • Thread starter Thread starter Guest
  • Start date Start date
George said:
Thansk Andy,


I would like to try some function which is Microsoft built-in. :-)


Do you have any experiences of using TextWriterTraceListener?

http://msdn2.microsoft.com/en-us/library/system.diagnostics.textwritertracelistener.aspx

Does it provide any function of limit the size of log? If it does not
provide the function, are there any way to implement the size limit function
application code?
No, I have never used it. From looking at the doc, I don't see a
limitation for the file size, too

Perhaps it is an option for you to implement a custom trace listener.
All you have to do (sounds simple :-) )is to derive from TraceListener
and implement the desired methods. You have to to the "ringbuffer"
writing yourself.

If you want to stick to MS stuff, how about the enterprise logging
application block?

HTH,
Andy
 
Thanks Andy,


The Enterprise Logging Application Block -- I have downloaded it, but I am
not sure whether it is too complex to use, and too much overhead. Since the
application I developed is only 60-70k, and I do not want the logging
component to add too much overhead to the application. How do you think
whether Enterprise Logging Application Block will add too much overhead to my
application?

Another concern is, if I use Enterprise Logging Application Block to my
application, will the customer who use the application has any additional
dependencies -- will they install any additional Runtime components (to
support Enterprise Logging Application Block ) in order to use the
application I developed?


regards,
George
 
George said:
Thanks Andy,


The Enterprise Logging Application Block -- I have downloaded it, but I am
not sure whether it is too complex to use, and too much overhead. Since the
application I developed is only 60-70k, and I do not want the logging
component to add too much overhead to the application. How do you think
whether Enterprise Logging Application Block will add too much overhead to my
application? I have no experience here.

Another concern is, if I use Enterprise Logging Application Block to my
application, will the customer who use the application has any additional
dependencies -- will they install any additional Runtime components (to
support Enterprise Logging Application Block ) in order to use the
application I developed?
AFAIK, nothing expect the assemblies of the application block itself.

If you are concerned about overhead and deployment I'd suggest again
log4net. It has a small runtime overhead (less that Trace) an you only
have to deploy one additional dll.

HTH,
Andy
 
The bank where I work as a software architect uses Log4Net extensively and
it's very reliable and simple to use.

--
--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
 
Hello everyone,

I am using C# and Visual Studio 2005 to develop a class library. I am
wondering whether there are any built-in log component in C# so that I can
utilize directly other than write from scratch?

I am also wondering if there does exist such log component, if multiple
processes using the built-in log component to open the same log file to write
log (in my application, I want all processes which loads the class library
DLL to have a common log file), will there be any risk of racing condition
(e.g. interlacing log of one process and another process)? Do we need any
lock/synchronization approach?

thanks in advance,
George

I'm a big fan of the System.Diagnostics tracing classes. Typical
usage is to instantiate the TraceListener derived class for the
storage medium you want to you use (e.g., EventLogTraceListener to
write to the windows event log, TextWriterTraceListener to write to a
file) then conditionally trace based on a TraceSwitch.

You can automatically configure trace switches and listeners from your
app.config file.

A few caveats: TextWriterTraceListener uses exclusive access to the
file so you'll have to use one of its other constructors to specify
shared access, you'll have to handle synchronization yourself, be
careful with the EventLogTraceListener as it can easily fill up the
windows event log in a space constrained situation.

Code-wise what you'll end up with is lots of statements like:

Trace.WriteLineIf(switch.TraceInfo, "....")

where you set the value of the trace switch in your app config file,
instantiate it and add listeners via config file or programmatically
to your listener collection.
 
Back
Top