是否可以忽略日志文件中的现有消息。我有这样的配置:
<appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
<file value="Logs\\" />
<lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%-5p %d{dd-MM-yyyy hh:mm:ss} [%thread] %level %logger - %message%newline" />
</layout>
<datePattern value="'EmailWatcher.'dd.MM.yyyy'.log'" />
<staticLogFileName value="false" />
<appendToFile value="true" />
<rollingStyle value="Composite" />
<maxSizeRollBackups value="10" />
<maximumFileSize value="5MB" />
<filter type="log4net.Filter.LevelRangeFilter">
<levelMin value="INFO" />
<levelMax value="WARN" />
</filter>
</appender>
<appender name="ErrorLogFileAppender" type="log4net.Appender.RollingFileAppender">
<file value="Logs\\" />
<lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%-5p%d{ yyyy-MM-dd HH:mm:ss} – [%thread] %m method: %method %n stacktrace: %stacktrace{5} %n type: %type %n line: %line %n" />
</layout>
<datePattern value="'EmailWatcher.'dd.MM.yyyy'.log'" />
<staticLogFileName value="false" />
<appendToFile value="true" />
<rollingStyle value="Composite" />
<maxSizeRollBackups value="10" />
<maximumFileSize value="5MB" />
<filter type="log4net.Filter.LevelRangeFilter">
<levelMin value="ERROR" />
<levelMax value="FATAL" />
</filter>
</appender>
<root>
<level value="INFO" />
<appender-ref ref="RollingLogFileAppender" />
<appender-ref ref="ErrorLogFileAppender" />
</root>
是否有任何现有方法可以检查消息是否已经存在,如果不存在则添加,否则忽略。当前的应用程序每隔x分钟运行一次并记录消息,但会使日志文件混乱。
INFO 04-12-2018 03:57:26 [12] INFO App - Connected to mailbox server...
INFO 04-12-2018 03:57:26 [12] INFO App - Looking for folder named 'Working'
INFO 04-12-2018 03:57:27 [12] INFO App - Connected to folder 'Working'
INFO 04-12-2018 03:57:27 [12] INFO App - Total items in the folder 'Working' is: 0
INFO 04-12-2018 03:57:52 [10] INFO App - Connecting to mailbox Office 365
INFO 04-12-2018 03:57:58 [10] INFO App - Connected to mailbox server...
INFO 04-12-2018 03:57:58 [10] INFO App - Looking for folder named 'Working'
INFO 04-12-2018 03:57:59 [10] INFO App - Connected to folder 'Working'
INFO 04-12-2018 03:57:59 [10] INFO App - Total items in the folder 'Working' is: 0
我尝试使用过滤器,但不知道如何进行。谢谢。