George2

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



Re: .NET Base Class Library C# log component

SThotakura2

Did you consider Logging Application Block It has so many things like logging to text file, database, email....

Please check the following link

http://msdn2.microsoft.com/en-us/library/aa480464.aspx

Cheers





Re: .NET Base Class Library C# log component

vtortola

You can use System.Diagnostics.Trace, add a TextWriterTraceListener to the listeners collections, and it will write in a file all you write in for example Trace.Write()

http://msdn2.microsoft.com/es-es/library/system.diagnostics.textwritertracelistener(VS.80).aspx

It's simple, threadsafe, easy and clear.

Regards.





Re: .NET Base Class Library C# log component

George2

Thanks SThotakura2,

SThotakura2 wrote:

Did you consider Logging Application Block It has so many things like logging to text file, database, email....

Please check the following link

http://msdn2.microsoft.com/en-us/library/aa480464.aspx

Cheers

From the introduction of the component, it over-satisfies the requirements. I just want simple log function to a local file, and it should be thread/process safe when they accessing the same file.

I am wondering whether the Logging Application Block will degrade the performance since it provides so many functions I only need basic ones :-)

regards,

George





Re: .NET Base Class Library C# log component

George2

Hi vtortola,

vtortola wrote:
You can use System.Diagnostics.Trace, add a TextWriterTraceListener to the listeners collections, and it will write in a file all you write in for example Trace.Write()

http://msdn2.microsoft.com/es-es/library/system.diagnostics.textwritertracelistener(VS.80).aspx

It's simple, threadsafe, easy and clear.

Regards.

When I open this page, it is not English. I have tried to find the related English page, but failed. Could you provide a link in English please

regards,

George





Re: .NET Base Class Library C# log component

vtortola

George2 wrote:


When I open this page, it is not English. I have tried to find the related English page, but failed. Could you provide a link in English please

regards,

George




Ops! i'm sorry Stick out tongue

http://msdn2.microsoft.com/en-us/library/system.diagnostics.textwritertracelistener(VS.80).aspx


Regards.





Re: .NET Base Class Library C# log component

George2

Thanks vtortola,

Looks like it is what I am looking for. I am wondering whether it is thread and process safe If not, I have to add locking and synchronization approach from application code.

regards,

George

vtortola wrote:

George2 wrote:


When I open this page, it is not English. I have tried to find the related English page, but failed. Could you provide a link in English please

regards,

George




Ops! i'm sorry

http://msdn2.microsoft.com/en-us/library/system.diagnostics.textwritertracelistener(VS.80).aspx


Regards.




Re: .NET Base Class Library C# log component

vtortola

Yes it's.

You can call Trace methods from several threads, you don't need extra synchronization.

Regards.





Re: .NET Base Class Library C# log component

George2

Thanks vtortola,

vtortola wrote:
Yes it's.

You can call Trace methods from several threads, you don't need extra synchronization.

Regards.

How about the cross-process locking/synchrozation approach Is it supported in trace writer

regards,

George





Re: .NET Base Class Library C# log component

ChunSheng Tang - MSFT

Hi, George

The TraceListener does not support cross-process synchronization, however you can use a named Mutex to accomplish it.

Best Regards

Chunsheng Tang