Connecting Tech Pros Worldwide Help | Site Map

C# log component

=?Utf-8?B?R2Vvcmdl?=
Guest
 
Posts: n/a
#1: Sep 15 '07
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
Marc Gravell
Guest
 
Posts: n/a
#2: Sep 15 '07

re: C# log component


You could try nlog: http://www.nlog-project.org/

Regarding the race condition - I believe most logging components will
worry about this on your behalf.

Marc

Morten Wennevik [C# MVP]
Guest
 
Posts: n/a
#3: Sep 15 '07

re: C# log component


On Sat, 15 Sep 2007 11:12:00 +0200, George <George@discussions.microsoft.comwrote:
Quote:
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.

--
Happy coding!
Morten Wennevik [C# MVP]
Andreas Mueller
Guest
 
Posts: n/a
#4: Sep 15 '07

re: C# log component


Morten Wennevik [C# MVP] wrote:
Quote:
On Sat, 15 Sep 2007 11:12:00 +0200, George <George@discussions.microsoft.comwrote:
>
Quote:
>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.
>
I'm using log4net in a large multi threaded application and it works
perfect.

HTH,
Andy

--
You can email me by removing the NOSPAM parts below:
xmen40NOSPAM@gmxNOSPAM.net
DaveP
Guest
 
Posts: n/a
#5: Sep 15 '07

re: C# log component


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
"George" <George@discussions.microsoft.comwrote in message
news:0057F591-72F4-4E2E-A3AF-971ACB520366@microsoft.com...
Quote:
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

DaveP
Guest
 
Posts: n/a
#6: Sep 15 '07

re: C# log component


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


"DaveP" <dvs_bis@sbcglobal.netwrote in message
news:u7SGi.34227$RX.22273@newssvr11.news.prodigy.n et...
Quote:
>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
"George" <George@discussions.microsoft.comwrote in message
news:0057F591-72F4-4E2E-A3AF-971ACB520366@microsoft.com...
Quote:
>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
>
>

=?Utf-8?B?R2Vvcmdl?=
Guest
 
Posts: n/a
#7: Sep 15 '07

re: C# log component


Thanks Marc,


You mean Microsoft .Net has no built-in log function?


regards,
George

"Marc Gravell" wrote:
Quote:
You could try nlog: http://www.nlog-project.org/
>
Regarding the race condition - I believe most logging components will
worry about this on your behalf.
>
Marc
>
>
=?Utf-8?B?R2Vvcmdl?=
Guest
 
Posts: n/a
#8: Sep 15 '07

re: C# log component


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 [C# MVP]" wrote:
Quote:
On Sat, 15 Sep 2007 11:12:00 +0200, George <George@discussions.microsoft.comwrote:
>
Quote:
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.
>
--
Happy coding!
Morten Wennevik [C# MVP]
>
=?Utf-8?B?R2Vvcmdl?=
Guest
 
Posts: n/a
#9: Sep 15 '07

re: C# log component


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

"Andreas Mueller" wrote:
Quote:
Morten Wennevik [C# MVP] wrote:
Quote:
On Sat, 15 Sep 2007 11:12:00 +0200, George <George@discussions.microsoft.comwrote:
Quote:
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.
I'm using log4net in a large multi threaded application and it works
perfect.
>
HTH,
Andy
>
--
You can email me by removing the NOSPAM parts below:
xmen40NOSPAM@gmxNOSPAM.net
>
=?Utf-8?B?R2Vvcmdl?=
Guest
 
Posts: n/a
#10: Sep 15 '07

re: C# log component


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

"DaveP" wrote:
Quote:
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
"George" <George@discussions.microsoft.comwrote in message
news:0057F591-72F4-4E2E-A3AF-971ACB520366@microsoft.com...
Quote:
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
>
>
>
Morten Wennevik [C# MVP]
Guest
 
Posts: n/a
#11: Sep 15 '07

re: C# log component


On Sat, 15 Sep 2007 17:28:02 +0200, George <George@discussions.microsoft.comwrote:
Quote:
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 [C# MVP]" wrote:
>
Quote:
>On Sat, 15 Sep 2007 11:12:00 +0200, George <George@discussions.microsoft.comwrote:
>>
Quote:
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.
>>
>--
>Happy coding!
>Morten Wennevik [C# MVP]
>>
>
Not really. The closes thing is the Trace and Debug classes. But you need to write some code to make them good logging classes.

--
Happy coding!
Morten Wennevik [C# MVP]
=?Utf-8?B?R2Vvcmdl?=
Guest
 
Posts: n/a
#12: Sep 15 '07

re: C# log component


Thanks Morten,


I have found one,TextWriterTraceListener.

http://msdn2.microsoft.com/en-us/lib...elistener.aspx

After reading through this page, I am still a little confused about how to
use it step by step. Do you have a tutorial?


regards,
George

"Morten Wennevik [C# MVP]" wrote:
Quote:
On Sat, 15 Sep 2007 17:28:02 +0200, George <George@discussions.microsoft.comwrote:
>
Quote:
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 [C# MVP]" wrote:
Quote:
On Sat, 15 Sep 2007 11:12:00 +0200, George <George@discussions.microsoft.comwrote:
>
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.
>
--
Happy coding!
Morten Wennevik [C# MVP]
>
>
Not really. The closes thing is the Trace and Debug classes. But you need to write some code to make them good logging classes.
>
--
Happy coding!
Morten Wennevik [C# MVP]
>
Andreas Mueller
Guest
 
Posts: n/a
#13: Sep 15 '07

re: C# log component


George wrote:
Quote:
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

--
You can email me by removing the NOSPAM parts below:
xmen40NOSPAM@gmxNOSPAM.net
=?UTF-8?B?QXJuZSBWYWpow7hq?=
Guest
 
Posts: n/a
#14: Sep 15 '07

re: C# log component


George wrote:
Quote:
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
=?Utf-8?B?R2Vvcmdl?=
Guest
 
Posts: n/a
#15: Sep 16 '07

re: C# log component


Thanks Arne,


I want to use something simple. :-)

Do you have any experiences of TextWriterTraceListener?

http://msdn2.microsoft.com/en-us/lib...elistener.aspx

Is it thread and application safe?


regards,
George

"Arne Vajhøj" wrote:
Quote:
George wrote:
Quote:
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
>
=?Utf-8?B?R2Vvcmdl?=
Guest
 
Posts: n/a
#16: Sep 16 '07

re: C# log component


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/lib...elistener.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?


regards,
George

"Andreas Mueller" wrote:
Quote:
George wrote:
Quote:
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
>
--
You can email me by removing the NOSPAM parts below:
xmen40NOSPAM@gmxNOSPAM.net
>
=?Utf-8?B?R2Vvcmdl?=
Guest
 
Posts: n/a
#17: Sep 16 '07

re: C# log component


Thanks Andy,

I want to use some Microsoft built-in function. :-)

Do you have any experiences of using TextWriterTraceListener?

http://msdn2.microsoft.com/en-us/lib...elistener.aspx

Does it provide function of limit the size of log? If no such function
provided, how to implement from application code?


regards,
George

"Andreas Mueller" wrote:
Quote:
George wrote:
Quote:
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
>
--
You can email me by removing the NOSPAM parts below:
xmen40NOSPAM@gmxNOSPAM.net
>
Andreas Mueller
Guest
 
Posts: n/a
#18: Sep 16 '07

re: C# log component


George wrote:
Quote:
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/lib...elistener.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

--
You can email me by removing the NOSPAM parts below:
xmen40NOSPAM@gmxNOSPAM.net
=?UTF-8?B?QXJuZSBWYWpow7hq?=
Guest
 
Posts: n/a
#19: Sep 16 '07

re: C# log component


George wrote:
Quote:
I want to use something simple. :-)
>
Do you have any experiences of TextWriterTraceListener?
>
http://msdn2.microsoft.com/en-us/lib...elistener.aspx
>
Is it thread and application safe?
I have not tried it.

The link you gave say:

Thread Safety
Any public static (Shared in Visual Basic) members of this type
are thread safe. Any instance members are not guaranteed to be
thread safe.

Arne
Bob Powell [MVP]
Guest
 
Posts: n/a
#20: Sep 17 '07

re: C# log component


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.


"Morten Wennevik [C# MVP]" <MortenWennevik@hotmail.comwrote in message
news:op.tyox14bidj93y5@ubuan...
Quote:
On Sat, 15 Sep 2007 11:12:00 +0200, George
<George@discussions.microsoft.comwrote:
>
Quote:
>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.
>
--
Happy coding!
Morten Wennevik [C# MVP]
Arnshea
Guest
 
Posts: n/a
#21: Sep 17 '07

re: C# log component


On Sep 15, 5:12 am, George <Geo...@discussions.microsoft.comwrote:
Quote:
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.

Closed Thread