提高::登录add_file_log不CTRL_CLOSE_EVENT写,如果应用程序退出 [英] boost::log add_file_log not writing if app exits with CTRL_CLOSE_EVENT

查看:192
本文介绍了提高::登录add_file_log不CTRL_CLOSE_EVENT写,如果应用程序退出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Windows 7中,使用boost ::登录v1.54在控制台应用程序。我使用add_file_log()与旋转,这很好,只要可以作为我的main()函数退出。但是,如果应用程序是使用PowerShell CloseMainWindow()外部终止,日志文件永远不会被写入。

我已经设置了使用SetConsoleCtrlHandler()Windows控件处理程序,可以捕获CTRL_CLOSE_EVENT,但我不知道是否有一个boost ::日志的方法我可以打电话强制日志文件之前,我的应用程序编写退出。有没有人有一个解决方案?

谢谢,

 罗布


解决方案

您可能想看看两件事。以下是根据我的经验

1)日志文件存在,但为空。在这种情况下使用auto_flush作为创建日志消息到日志刷新到磁盘。其他明智的,你可以用一个空的记录结束了,如果没有,当发生CTRL_CLOSE_EVENT被刷新足够的日志信息。

2)日志文件退出,但不是被你认为它是。在这种情况下,确保日志文件在同一目录作为目标目录中创建。目标目录收集日志文件时,汇被关闭。如果关键字FILE_NAME设置为仅会在工作目录中,而不是目标目录中创建一个文件名。如果应用程序退出而不关闭汇那么该文件将不会被移动到目标目录。

HTH,

I'm on Windows 7, using boost::log in v1.54 in a console application. I'm using add_file_log() with rotation, which works fine as long as my main() function exits. But if the app is terminated externally with powershell CloseMainWindow(), the log file never gets written.

I've set up a windows control handler using SetConsoleCtrlHandler(), and can trap CTRL_CLOSE_EVENT, but I don't know if there's a boost::log method I can call to force the log file to write prior to my app exiting. Does anyone have a solution for this?

Thanks,

  Rob

解决方案

Two thing you may want to look at. The following is based on my experience

1) The log file exists but is empty. In this case use auto_flush to flush the log to disk as the log messages are created. Other wise you could end up with an empty log if there is not enough log messages to be flushed when CTRL_CLOSE_EVENT occurs.

2) The log file exits but is not were you think it is. In this case make sure that the log file is created in the same directory as the target directory. The target directory collects the log files when the sinks are closed. If the keyword file_name is set to a file name only it will be created in the working directory, not the target directory. If the application exits without closing the the sinks then the file will not be moved to the target directory.

HTH,

这篇关于提高::登录add_file_log不CTRL_CLOSE_EVENT写,如果应用程序退出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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