log4net ForwardingAppender 阈值

发布于 2024-10-06 16:06:39 字数 2383 浏览 1 评论 0原文

我需要配置记录器将消息写入具有不同日志级别的多个附加程序。

对于前。我希望 RefreshDataService 将详细信息记录到 TransportFileAppender 并将警告和错误记录到 RollingFileAppender

另外,我使用缓冲来提高日志记录性能。 我设置 FilteredFileLog 附加程序将警告转发到 FileLog->RollingFileAppender。

但对于 RefreshDataService 记录器,所有日志消息(包括调试和信息)都会记录到 FileLog 中。

您能否帮助我配置 RefreshDataService 记录器以仅将 Warn+ 消息记录到 FileLog 中?谢谢。

以下是我的 log4net 配置的摘录。

<appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
  <file value="${TEMP}\logs\client\${ENV}\client.log" />
  <appendToFile value="true" />
  <rollingStyle value="Size" />
  <maxSizeRollBackups value="10" />
  <maximumFileSize value="4096KB" />
  <layout type="log4net.Layout.PatternLayout">
    <conversionPattern value="%date [%thread] %-5level [%property{ENV}] [%property{UID}] %logger - %message%newline" />
  </layout>
</appender>

<appender name="TransportAppender" type="log4net.Appender.RollingFileAppender">
  <file value="${TEMP}\logs\client\${ENV}\client.comm.log" />
  <appendToFile value="true" />
  <rollingStyle value="Size" />
  <maxSizeRollBackups value="10" />
  <maximumFileSize value="4096KB" />
  <layout type="log4net.Layout.PatternLayout">
    <conversionPattern value="%date [%thread] %-5level %logger - %message%newline" />
  </layout>
</appender>


<appender name="DetailedTransportLog" type="log4net.Appender.BufferingForwardingAppender">
  <threshold value="DEBUG" />
  <bufferSize value="200" />
  <appender-ref ref="TransportAppender" />
</appender>

<appender name="FileLog" type="log4net.Appender.BufferingForwardingAppender">
  <bufferSize value="20" />
  <lossy value="false" />
  <appender-ref ref="RollingFileAppender" />
</appender>

<appender name="FilteredFileLog" type="log4net.Appender.ForwardingAppender">
  <threshold value="WARN" />
  <appender-ref ref="FileLog" />
</appender>

<logger name="RefreshDataService" >
  <level value="DEBUG" />
  <appender-ref ref="FilteredFileLog" />
  <appender-ref ref="DetailedTransportLog" />
</logger>

I need to configure logger to write messages to several appenders with different Log Levels.

For ex. I want RefreshDataService to log detailed info to TransportFileAppender and Warnings and Errors to RollingFileAppender.

Also, I'm using buffering to improve logging performance.
I setup FilteredFileLog appender to forward Warnings to FileLog->RollingFileAppender.

But for RefreshDataService logger, all log messages including debug and Info getting logged to FileLog.

Can you help me to configure the RefreshDataService logger to log only Warn+ messages to FileLog? Thanks.

Below is excerpt from my log4net config.

<appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
  <file value="${TEMP}\logs\client\${ENV}\client.log" />
  <appendToFile value="true" />
  <rollingStyle value="Size" />
  <maxSizeRollBackups value="10" />
  <maximumFileSize value="4096KB" />
  <layout type="log4net.Layout.PatternLayout">
    <conversionPattern value="%date [%thread] %-5level [%property{ENV}] [%property{UID}] %logger - %message%newline" />
  </layout>
</appender>

<appender name="TransportAppender" type="log4net.Appender.RollingFileAppender">
  <file value="${TEMP}\logs\client\${ENV}\client.comm.log" />
  <appendToFile value="true" />
  <rollingStyle value="Size" />
  <maxSizeRollBackups value="10" />
  <maximumFileSize value="4096KB" />
  <layout type="log4net.Layout.PatternLayout">
    <conversionPattern value="%date [%thread] %-5level %logger - %message%newline" />
  </layout>
</appender>


<appender name="DetailedTransportLog" type="log4net.Appender.BufferingForwardingAppender">
  <threshold value="DEBUG" />
  <bufferSize value="200" />
  <appender-ref ref="TransportAppender" />
</appender>

<appender name="FileLog" type="log4net.Appender.BufferingForwardingAppender">
  <bufferSize value="20" />
  <lossy value="false" />
  <appender-ref ref="RollingFileAppender" />
</appender>

<appender name="FilteredFileLog" type="log4net.Appender.ForwardingAppender">
  <threshold value="WARN" />
  <appender-ref ref="FileLog" />
</appender>

<logger name="RefreshDataService" >
  <level value="DEBUG" />
  <appender-ref ref="FilteredFileLog" />
  <appender-ref ref="DetailedTransportLog" />
</logger>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

刘备忘录 2024-10-13 16:06:39

您可以在附加程序上使用级别范围过滤器:

<filter type="log4net.Filter.LevelRangeFilter">
    <levelMin value="WARN" />
    <levelMax value="FATAL" />
</filter>
<filter type="log4net.Filter.DenyAllFilter" />

我的理解是,Threshold 属性用于告诉附加程序在记录特定级别的消息时刷新缓冲区。通过这种方式,您可以确保错误立即写入数据库。

You can use a level range filter on the appender:

<filter type="log4net.Filter.LevelRangeFilter">
    <levelMin value="WARN" />
    <levelMax value="FATAL" />
</filter>
<filter type="log4net.Filter.DenyAllFilter" />

My understanding is that the Threshold property is used tell the appender to flush the buffer when messages of a certain level are logged. This way you can make for instance sure that errors are written immediately to the database.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文