开发者

Using log4net for multithreaded application

开发者 https://www.devze.com 2023-03-01 15:56 出处:网络
I have a application which uses .net Thread-pool to have multiple threads.It uses log4net 开发者_JS百科for write logs to a plain text file. Is it a good idea to use log4net for asynchronous logging li

I have a application which uses .net Thread-pool to have multiple threads.It uses log4net 开发者_JS百科for write logs to a plain text file. Is it a good idea to use log4net for asynchronous logging like this. Or do i need to have separate MSMQ implementation to append messages?


You can use log4net as-is for file-based logging for multi-threaded applications. The log messages from all the threads will be written to the same file. It can get a little confusing to read all the interspersed messages, but it's better than not having logging. You'll definitely want to log the thread ID in the appender format so you can tell which messages are coming from which thread.

There are probably more fancy things you can do to handle the logging for different threads, but I've never really had to go down that road. I prefer to stick with file-based logging, and having all the threads log to one file is easier to deal with than having each thread log to its own file, in my opinion.

0

精彩评论

暂无评论...
验证码 换一张
取 消