log4net - FileAppender writing new entries at the beginning of file

别说谁变了你拦得住时间么 提交于 2020-01-11 08:40:31

问题


Is is possible to configure FileAppender in log4net to add new entries at the beginning of log file? Currently it is adding entries at the end and reading newest entries requires scrolling whole log down. It would be more comfortable to read from the beginning.


回答1:


I don't know if that option is available in log4net (I wouldn't think so), but even if it's available I would advice against using it.

Appending to a file is a quite cheap operation. The bytes are just added to the end of the file. Prepending to a file on the other hand is rather expensive. The entire file has to be read and rewritten with the new data added at the beginning. This also means that it scales badly, i.e. the operation takes a lot longer when the file gets bigger.

If you want the entries displayed in a different order, you should look for that option in the program that is displaying the log, or look for a replacement that can display the entries in reverse order.




回答2:


Use BareTail to view your log files. It automatically scrolls to the bottom of the files you view.



来源:https://stackoverflow.com/questions/2041641/log4net-fileappender-writing-new-entries-at-the-beginning-of-file

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