如果您有一个使用log4net作为日志记录子系统的Web服务,并且您想要查看' tail'其中一种Web服务方法的日志 - 如何在不读取日志文件的情况下将log4net尾部放入操作内存?
答案 0 :(得分:1)
简短回答:有MemoryAppender
课程。将它的初始化添加到您的配置中并使用它。
长答案:there is LimitedMemoryAppender
,实现事件计数限制。然后:
logger = log4net.LogManager.GetLogger("main");
var memoryAppender = new LimitedMemoryAppender ("MemoryAppender");
var l = (Logger)logger.Logger;
l.AddAppender (memoryAppender);
var memoryAppender = l.GetAppender("MemoryAppender") as MemoryAppender;
var events = memoryAppender.GetEvents().ToList ();