登录多线程环境并进行测试 [英] Logging in multithreading environment and testing

查看:100
本文介绍了登录多线程环境并进行测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在以下情况下,请让我知道您对如何设计日志记录以及如何对其进行测试的建议.

Please let me know your suggestions about how to design logging and how to test it, in the following scenario.

我有一个可以被多个线程调用的API.一个线程对该API的一次调用会生成50 KB的日志.

I've an API which can be called by multiple threads. One call of this API by a single thread generates a log of 50 KB.

在多线程环境中是否存在用于登录的任何设计模式.即所有线程有一个日志文件,而每个线程有一个专用日志文件?

Does any design pattern exist for logging in multi-threaded environment. i.e one log file for all threads vs one dedicated log file for each thread?

并且,如何对该功能进行测试. (应该测试吗?)

And, How to do testing for this feature. (should it be tested?)

谢谢.

推荐答案

将您的日志记录实例包装在线程安全的单例中. 请勿使用双重检查锁定!另外,使用 log4net

Wrap your logging instance in a thread-safe singleton. Don't use double check locking! Also, it probably makes sense to use a logging library like log4net or Enterprise Library 5.

这篇关于登录多线程环境并进行测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆