x 天后删除日志文件 [英] Delete log files after x days

查看:21
本文介绍了x 天后删除日志文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用文件目标使用 Nlog 进行登录,例如 示例.如何在 X 天后删除文件而不存档?或者是否可以将文件归档到同一个文件夹?

I would like to log with Nlog using the file target like in this example. How can I realize a deletion of the files after X days without archiving them? Or is it possible to archive the files to the same folder?

推荐答案

您可以简单地使用内置的归档功能.除了当前日志之外,此设置还将保留 7 个旧日志文件.清理是由 NLog 自动完成的.

You could simply use the built-in archiving functionality. This setting will keep 7 old log files in addition to your current log. The cleanup is done by NLog automatically.

<?xml version="1.0" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

    <targets>
        <target name="file" xsi:type="File"
            layout="${longdate} ${logger} ${message}" 
            fileName="${basedir}/logs/logfile.txt" 
            archiveFileName="${basedir}/logs/log.{#}.txt"
            archiveEvery="Day"
            archiveNumbering="Rolling"
            maxArchiveFiles="7"
            concurrentWrites="true" />
    </targets>

    <rules>
        <logger name="*" minlevel="Debug" writeTo="file" />
    </rules>
</nlog>

另见文件目标

这篇关于x 天后删除日志文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆