Microsoft Logging application block and multi-threading

白昼怎懂夜的黑 提交于 2020-01-30 06:46:48

问题


I am new to the Logging application block (4.1). Has anyone written an application that uses the Logging application block from multiple threads? I am asking because the Logger is a static class and because of potential writing to the same log file from multiple threads for example.


回答1:


The Logging Application Block is thread safe, meaning you can call its public methods from multiple threads without doing any synchronization of your own. The library does its own synchronization.




回答2:


I am not too sure why you are concerned that this might happen. As long as you provide a category for your logging messages those should be written to the appropriate logging file configured for that category. This operation is thread safe.

Or are you talking about writing the logging messages of the same category to different files by thread? E.g. thread 1 -> mylog-1.log; thread 2 -> mylog-2.log



来源:https://stackoverflow.com/questions/685039/microsoft-logging-application-block-and-multi-threading

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!