C# log component

G

Guest

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
 
M

Morten Wennevik [C# MVP]

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

Hi George,

In addition to Marc's suggestion there is also log4net

http://logging.apache.org/log4net/index.html

I haven't tried logging to file, but it seems robust enough that numerous logging sources should not be a problem.
 
D

DaveP

i wrote my own..logging....multi threaded service
1st thread starts the logging...all other services open and share the
log....
in my log class,
i wrote...
1. if can't log to sq db , 2 if i cant write to text file , 3 if that fails
in my app.config
1. i have sql serve connection string for log (table)
2. path and file name for log files (text files)

if you want to see the class....let me know
its work in progress..since im only about 1 year with c# net...all other
experience was win32, languages

DaveP


DaveP

write to event log
 
D

DaveP

i typed the last comment all messed up
what i actually do is
1 try to write to my errorsdb..log table
if fails
2. try to write to app defined text file log
if that fails
3 try to write to machine event log
if all 3 of the above fails... well somthing is really broken

i never write to all 3 at once....some people do...
i just think that is a waist of time and resources

DaveP
 
G

Guest

Thanks Morten,


You mean Microsoft .Net itself does not provide log function? I only need to
log to a local file.


regards,
George
 
G

Guest

Thanks Andy,


Does it provide function to keep log size to some threshold? I do not want
the log file too big. Thanks.


regards,
George
 
G

Guest

Thanks for your kindness DaveP!


I have only used for C# for half a year. If possible, could I learn your
code please? From your description, it looks like what I am looking for.


regards,
George
 
G

Guest

Thanks DaveP,


Why you use the special order (db, text and event log)? Any reasons to
design like this?


regards,
George
 
D

DaveP

i did that order....since all my services are back end services, for web and
processing of data comming into the site (transactions and other
information)
the reason i only write 1 place ....is why write all 3 places
when only 1 will suffice.....less use on resources and performance
reasons....

i write to the sql log..our database..table (not sqls log)
this lets us have a interface to the web site under admin mode..to monitor
all the processing services...

if i can't connect with the db when i write a log entry...the log class
writes the current entry to a text file on the shared folder where logs are
located...if i can't write to our text file logs...i then write the error /
entry to the machine event handler.....
hope that makes more sense to ya
Davep
send me a email to dvs_bis ~ sbcglobal.net
replace the ~ with @
i'll be glad to send the code to ya
 
M

Morten Wennevik [C# MVP]

Thanks Morten,


You mean Microsoft .Net itself does not provide log function? I only need to
log to a local file.


regards,
George

Morten Wennevik said:
Hi George,

In addition to Marc's suggestion there is also log4net

http://logging.apache.org/log4net/index.html

I haven't tried logging to file, but it seems robust enough that numerous logging sources should not be a problem.

Not really. The closes thing is the Trace and Debug classes. But you need to write some code to make them good logging classes.
 
G

Guest

Thanks DaveP,


Looks like your code is very comprehensive and tested with real application.
I am sending you an email. Thanks again!


have a good weekend,
George
 
A

Andreas Mueller

George said:
Thanks Andy,


Does it provide function to keep log size to some threshold? I do not want
the log file too big. Thanks.

Yes, you can limit the size and also let the file appender roll. You can
specify multiple appenders, e.g. for sending your log output to the
console or a trace window.

It's very simple to configure and has a good performance.

HTH,
Andy
 
G

Guest

George said:
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?

You can get a "Logging Application Block" in "Enterprise Library"
from Microsoft.

But I would recommend log4net.

Arne
 

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