Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which is the most performance based method of writing logs for Application

I am working in a client server application in which multiple clients and server are working on socket based communication for financial transactions where performance is very critical. Currently I am using streamwriter of system.IO namespace to write logs in file. For a single transaction I need to call streamwriter method 50 times to log different value and for more than 50,000 transactions, time taken for this logging become very important.

How can I reduce time taken by application to do logging? Whether I need to choose some other approach or any other class instead of streamwriter? What will be the best way to do logging with lesser time.

like image 770
funsukvangdu Avatar asked Jan 22 '13 10:01

funsukvangdu


People also ask

What should be logged in an application?

These logs typically consist of the following information: date and time, requester identity such as User ID and IP address or referral URL, and the actual request data. In the case of a Web Application or API, the requested endpoint URL and context header and body is logged.

Does logging affect performance?

As I've pointed out in my previous blog post, logging can have a huge performance impact and in general should rather be avoided. The following examples are therefore NOT considered to be best practice, but rather a comparison of different ways to implement plain-text auditing in cases where you're required to do so.

Does logging slow down performance?

Logging does have its drawbacks also. It can slow down an application as it uses some CPU cycles and other resources (memory, etc). To answer these concerns, log4j is designed to be reliable, fast and extensible. Also, one should only log an error or something that must absolutely be logged.


2 Answers

If performance is key, then I would consider looking at Event Tracing for Windows (AKA ETW).

With .NET 4.5 and the introduction of the EventSource class this has made ETW much easier to implement than in the past.

Vance Morrison's Weblog has some good articles on this topic.

For an overview of the architecture see Improve Debugging And Performance Tuning With ETW.

There is also the Semantic Application Block from Microsoft's patterns & practices team that makes it easier to incorporate the EventSource functionality and to manage logging behavior.

like image 179
Randy supports Monica Avatar answered Sep 18 '22 02:09

Randy supports Monica


I suggest you to try Log4Net, you can configure where (file, database, xml) and when (bath, transaction, ...) and easily switch tracing level (debug, info, warning, ...)

Writing a log system from scratch is not worth it.

like image 22
Stefano Altieri Avatar answered Sep 19 '22 02:09

Stefano Altieri