作者热门文章
- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我在 Windows Server 2012 R2 上使用 nxlog-ce。
nxlog 正在输出两个 txt 文件。
我想每小时轮换这两个文件。我希望事件日志保持相同的名称,logfileA.txt logfileB.txt 和要创建的新旋转文件 logfileA.txt.2 logfileB.txt.2
我只希望每个日志有两个文件 logfileA.txt 和 logfileA.txt.2 但绝不是 logfileA.txt.3
这是我当前的 nxlog.config 中的重要部分
define LOGFILE_Atxt C:\test\logfileA.txt
define LOGFILE_Btxt C:\test\logfileB.txt
<Extension fileop>
Module xm_fileop
<Schedule>
Every 1 hour
Exec file_cycle('%LOGFILE_Atxt%', 2);
Exec file_cycle('%LOGFILE_Btxt%', 2);
</Schedule>
</Extension>
<Output loga_out>
Module om_file
file 'c:\test\logfileA.txt'
CreateDir TRUE
</Output>
<Output logb_out>
Module om_file
file 'c:\test\logfileB.txt'
CreateDir TRUE
</Output>
<Route loga_route>
Path loga_input => loga_out
</Route>
<Route logb_route>
Path logb_input => logb_out
</Route>
在此配置中,当 nxlog 服务启动时,它会立即创建 logfileA.txt.1 和 logfileB.txt.1但是,系统从不轮换日志。永远不会创建 logfileA.txt.2 和 logfileB.txt.2。
我无法找到有关如何使用 nxlog 设置日志轮换的资源。
非常感谢任何帮助。谢谢!
最佳答案
我认为问题在于 om_file 不断写入旋转文件。您需要通知它,以便它重新打开其输出。以下应该有效:
<Extension fileop>
Module xm_fileop
</Extension>
<Output loga_out>
Module om_file
file 'c:\test\logfileA.txt'
CreateDir TRUE
<Schedule>
Every 1 hour
Exec file_cycle('%LOGFILE_Atxt%', 2);
Exec loga_out->reopen();
</Schedule>
</Output>
<Output logb_out>
Module om_file
file 'c:\test\logfileB.txt'
CreateDir TRUE
<Schedule>
Every 1 hour
Exec file_cycle('%LOGFILE_Btxt%', 2);
Exec logb_out->reopen();
</Schedule>
</Output>
关于windows - 轮转由 nxlog 创建的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32999592/
我有一个在 Linux(Debian、Ubuntu 和 RHEL)上使用 log4j 的 Spring 项目。现在我想为 log4j 生成的日志实现最佳实践日志轮换。 我以前曾将 logrotate.
我是一名优秀的程序员,十分优秀!