Simple MultiThread Safe Log Class
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: What is the best approach to creating a simple multithread safe logging class? Is something like this sufficient? How would I purge the log when it's initially created? public class Logging { public Logging () { } public void WriteToLog ( string message ) { object locker = new object (); lock ( locker ) { StreamWriter SW ; SW = File . AppendText ( "Data\\Log.txt" ); SW . WriteLine ( message ); SW . Close (); } } } public partial class MainWindow : Window { public static MainWindow Instance { get ; private set ; } public Logging Log