简体   繁体   English

C# WPF 应用程序中的 Log4Net 控制台附加程序

[英]Log4Net Console Appender in C# WPF Application

I have a WPF application, where RollingFileAppender works fine in logging the messages to a log file.我有一个 WPF 应用程序,其中 RollingFileAppender 可以很好地将消息记录到日志文件中。 However I am trying to retrieve only INFO level logs and display them in a WPF window.但是我试图只检索 INFO 级别的日志并将它们显示在 WPF window 中。 I have tried with NotifyAppender, COnsole Appender, none of them works as expected.我已经尝试过 NotifyAppender、CONsole Appender,它们都没有按预期工作。 Can anyone suggest what would be the correct approach for this, where a WPF window or console window will pop up and show the real time INFO logs.谁能建议什么是正确的方法,其中 WPF window 或控制台 window 将弹出并显示实时信息日志。

You could use a filter to achieve what you describe:您可以使用过滤器来实现您所描述的内容:

<appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender">
  <filter type="log4net.Filter.LevelRangeFilter">
    <levelMin value="INFO" />
    <levelMax value="INFO" />
  </filter>
</appender>

This will show only INFO messages in a console window.这将仅在控制台 window 中显示 INFO 消息。

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

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