log4net 不会为引用的项目文件创建日志文件

发布于 2024-09-09 06:49:13 字数 232 浏览 7 评论 0原文

我正在构建一个调用已编译的可执行文件的应用程序。所述可执行文件的源代码项目文件由父应用程序的解决方案文件引用。子可执行文件是一个独立的命令行应用程序。父级实际上是控制台应用程序的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

风流物 2024-09-16 06:49:13

要使 log4net 在引用的程序集中开始记录,您必须:

  • 通过在以下情况下调用 log4net.Config.XmlConfigurator.Configure() 来调用 log4net 的 Configure() 函数:应用程序启动,或者通过将 [assemble: log4net.Config.XmlConfigurator(Watch=true)] 添加到包装器应用程序的 AssemblyInfo.cs 文件中。
  • 如果您还没有这样做,请在您的 GUI 包装器的 app.config 中创建一个 log4net 配置部分。将 app.config 文件添加到您的项目中,并将 log4net 配置信息从引用的库复制到其中。
  • 确保运行应用程序的帐户有权在日志目录中写入和创建文件(假设您使用基于文件的日志记录)。

有关设置配置的更多信息,请参阅:http://logging.apache.org /log4net/release/manual/configuration.html

For log4net to start logging within the referenced assembly you will have to:

  • Call the Configure() function of log4net by either calling log4net.Config.XmlConfigurator.Configure() when your application starts, or by adding [assembly: log4net.Config.XmlConfigurator(Watch=true)] to the AssemblyInfo.cs file of your wrapper application.
  • Create an log4net configuration section in the app.config for your GUI wrapper if you haven't already done so. Add an app.config file to your project, and copy your log4net configuration information from the referenced library into it.
  • Ensure that the account running the application has access to write and create files within the log directory (assuming your using file-based logging).

For more info about setting up your config see: http://logging.apache.org/log4net/release/manual/configuration.html

知你几分 2024-09-16 06:49:13

我知道现在已经太晚了,但无论如何仅供参考。
在应用程序中设置 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)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文