log4net 不会为引用的项目文件创建日志文件
我正在构建一个调用已编译的可执行文件的应用程序。所述可执行文件的源代码项目文件由父应用程序的解决方案文件引用。子可执行文件是一个独立的命令行应用程序。父级实际上是控制台应用程序的 GUI 包装器。当我编译控制台应用程序时,我可以访问应用程序中内置的所有 log4net 功能。但是,当我编译引用控制台应用程序源代码文件的父项目时,一切都运行正常,但没有生成日志。什么会导致此错误发生?如何修复此错误? log4net 的内部调试机制不会抛出任何消息。
I am building an application that calls upon a compiled executable. Said executable's source code project file is referenced by the solution file for the parent application. The child executable is a stand alone command line application. The parent is a effectively a GUI wrapper to the console application. When I compile the console application, I have access to all of log4net's functionality that has been built into the application. However, when I compile the parent project that references the console application's source code files, everything runs correctly but no logs are generated. What would cause this error to occur, and how can this occurrence be fixed? log4net's internal debugging mechanism doesn't throw any messages.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
要使 log4net 在引用的程序集中开始记录,您必须:
log4net.Config.XmlConfigurator.Configure()
来调用 log4net 的Configure()
函数:应用程序启动,或者通过将[assemble: log4net.Config.XmlConfigurator(Watch=true)]
添加到包装器应用程序的AssemblyInfo.cs
文件中。有关设置配置的更多信息,请参阅:http://logging.apache.org /log4net/release/manual/configuration.html
For log4net to start logging within the referenced assembly you will have to:
Configure()
function of log4net by either callinglog4net.Config.XmlConfigurator.Configure()
when your application starts, or by adding[assembly: log4net.Config.XmlConfigurator(Watch=true)]
to theAssemblyInfo.cs
file of your wrapper application.For more info about setting up your config see: http://logging.apache.org/log4net/release/manual/configuration.html
我知道现在已经太晚了,但无论如何仅供参考。
在应用程序中设置 log4net.Internal.Debug = true,您可能会在控制台上看到问题。 (以编程方式执行此操作,因为您的应用程序可能无法找到它的配置文件,这就是我的情况发生的情况)
在 Process p 上,在使用 p.start() 执行进程后,尝试使用以下命令将标准输出写入控制台;
Console.write(p.StandardOutput.ReadToEnd());
您应该能够看到问题所在。 (为什么 log4net 没有被配置或者为什么它没有记录)
就我而言,它正在父进程的工作目录中查找 app.config 文件。 (我的应用程序及其配置存在于文件系统的其他位置)
I know it's too late but anyway just for reference.
Set log4net.Internal.Debug = true in your application and you might see the problem on the console. (do this programmatically since your application might not be able to find it's config file, which was what happened in my case)
On the Process p, after you exec the process using p.start() try to write the stdout to console with this;
Console.write(p.StandardOutput.ReadToEnd());
You should be able to see the problem. (why log4net isn't getting configured or why it isn't logging)
In my case it was looking for the app.config file in the parent process's working directory. (my app and it's config are present elsewhere on the file system)