简体   繁体   English

log4net:为每个翻转日志段写一个标题

[英]log4net: writing a header to each rollover log segment

I have a RollingFileAppender that rolls over the log file when it reaches a specified file size. 我有一个RollingFileAppender,它在达到指定的文件大小时翻过日志文件。 This works great. 这非常有效。

Is there a way to have log4net insert a header at the top of each newly created log file? 有没有办法让log4net在每个新创建的日志文件的顶部插入一个标题? Alternatively, is there a way to be notified by log4net when a roll over occurs so that I can write this header myself? 或者,是否有一种方法可以在发生翻转时通过log4net进行通知,以便我可以自己编写此标头?

This seems to work: 这似乎有效:

<layout type="log4net.Layout.PatternLayout">
     <header value="[Header]&#13;&#10;" />
     <conversionPattern value=" ... " />
</layout>

Though it will also write the header if you re-start the application. 虽然如果重新启动应用程序,它也会写入标题。

我认为你可能需要扩展一个appender或为此编写自己的appender。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM