混合 log4cxx 和 log4net
我有一个 C++ 应用程序,它使用 log4cxx (RollingFile 附加程序)记录到某个文件。 我想同时从用 c# 编写的另一个模块登录到同一个文件; 所以我将 log4net 配置为使用相同的文件,但我无法获取新消息。如果我停用 C++ 日志记录,我可以看到 C# 消息。 所以我认为这是一个锁定问题,并寻找一个配置选项来告诉 log4cxx 不要锁定文件。 我进入了 log4net 的 MinimalLock 模型,但在 log4cxx 中找不到任何内容...有人知道它是否可以完成,以及如何完成?
提前致谢,
埃内斯托·卡伦
I have a c++ application which logs to some file using log4cxx (RollingFile appender). I want to log into the same file, at the same time, from another module written in c#; so i configured log4net to use the same file, but i can't get the new messages in. If i deactivate the c++ logging, i can see c# messages. So i think it is a locking issue, and looked for a configuration option to tell log4cxx not to lock the file. I came into MinimalLock model for log4net, but couldn't find anything in log4cxx... does anybody know if it could be done, and how?
thanks in advance,
Ernesto Cullen
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为,无论您使用什么配置,只要您尝试让两个不同的进程记录到同一个文件,您都可能会遇到并发和争用问题。
您应该考虑将日志事件从两个进程发送到第三个集中位置 - 看看 RemotingAppender ,我认为 log4cxx 有类似的东西。
I think that you might run into concurrency and contention problems no matter what configuration you use as long as you are attempting to have two different processes log to the same file.
You should look into sending log events from both processes to a third, centralized location - take a look at RemotingAppender in log4net, I assume log4cxx has something similar.
即使问题很老(并标记为已回答),并且您可能已经完成了您的项目:
log4net 和 log4cxx 是不同的日志框架,彼此不了解,因此您无法将它们配置为写入相同的文件。 只有其中一个框架会打开文件进行写入,以先到者为准。
我在类似情况下所做的(使用 log4net 自定义记录新的 c# 模块的旧版 c++ 应用程序)是 创建一个自定义 log4net 附加程序,将跟踪转发到旧的日志记录框架中。 在我参与的项目中,旧的 C++ 代码有一个 Windows COM 接口,用于编写自定义附加程序使用的日志消息。
另一种方法是使用 C++/CLI 创建自定义附加程序。
Even if the question is quite old (and marked as answered) and you're probably already finished with your project:
log4net and log4cxx are distinct logging framworks that don't know of each other so you can't configure them to write to the same file. Only one of the framworks will have the file open for writing, whichever was first.
What I have done in a similar situation (a legacy c++ application with custom logging an a new c# module using log4net) is create a custom log4net appender that forwards traces into the old logging framework. In the project where I was involved the old C++ code had a Windows COM Interface for writing log messages which the custom appender used.
Another way would be using C++/CLI to create the custom appender.