Vb.net Visual Studio 2008 log4net 多个模块,相同的 app.config 不同的记录器,不起作用
我在同一目录中有 2 个控制台应用程序项目,但项目不同。 App_Code 目录中有一些通用代码,还有一个通用的 app.config,它构建到单独的 .exe.config 文件中。
一个模块 (VScanDemonStarter) 启动并写入一个记录器,其自己的附加程序将写入一个单独的文件。它使用 process.start() 在另一个命令提示符隐藏窗口中执行另一个模块 (VScanDemon)。
当我单独运行 VScanDemon 时,它会将条目放入其日志文件中。当我运行 VScanDemonStarter 时,它将条目放入其(不同的)日志文件中,创建 VScanDemon 日志文件,但没有条目。我可以看到它正在执行,因为某些文件从一个目录移动到另一个目录。只是没有日志条目。
配置看起来像
<root>
<level value="INFO" />
</root>
<appender name="LogFileAppender" type="log4net.Appender.RollingFileAppender" >
<param name="File" value="log/vscandemonstarter.log" />
<param name="AppendToFile" value="true" />
<rollingStyle value="Size" />
<maxSizeRollBackups value="10" />
<maximumFileSize value="10MB" />
<staticLogFileName value="true" />
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%-5p %d{yyyy-MM-dd hh:mm:ss} - %m%n" />
</layout>
</appender>
<appender name="vsdemonlogfileappender" type="log4net.Appender.RollingFileAppender" >
<param name="File" value="log/vscandemon.log" />
<param name="AppendToFile" value="true" />
<rollingStyle value="Size" />
<maxSizeRollBackups value="10" />
<maximumFileSize value="10MB" />
<staticLogFileName value="true" />
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%-5p %d{yyyy-MM-dd hh:mm:ss} - %m%n" />
</layout>
</appender>
代码主体设置并调用主体。
VScanDemonStarter:
模块顶部:
Private ReadOnly log As ILog = log4net.LogManager.GetLogger("default")
主要顶部:
log4net.Config.XmlConfigurator.Configure()
示例调用:
If log.IsInfoEnabled Then log.Info("VScanDemonStarter:Main: ----called----")
VBScanDemon:
模块顶部:
Private ReadOnly log As ILog = log4net.LogManager.GetLogger("VSDemonLogger")
主要顶部:
log4net.Config.XmlConfigurator.Configure()
VBScanDemon:
If log.IsInfoEnabled Then log.Info("VScanDemon:Main: ----called----")
我没有从 VScanDemon 获得任何日志条目。
抱歉,遗漏了配置的顶部,
<log4net debug="true">
<logger name="default">
<level value="INFO"/>
<appender-ref ref="LogFileAppender" />
</logger>
<logger name="VSDemonLogger">
<level value="INFO"/>
<appender-ref ref="vsdemonlogfileappender" />
</logger>
我有一个 app.config,但同一目录中有两个项目使用它。它们从一个源 .exe.config 生成单独的配置。
我查看了 VScanDemon 的控制台输出,看起来它正在毫无问题地获取配置。但仍然是一个空日志。不知道是否需要加个冲水什么的。
I have 2 console apps projects in the same directory but different projects. There is some common code in the App_Code directory and a common app.config which gets build into seperate .exe.config files.
One module (VScanDemonStarter) starts up and writes to one logger with its own appender going to a seperate file. It uses an process.start() to execute the other module (VScanDemon) in another command prompt hidden window.
When I run VScanDemon by itself it puts entries into its log file. When I run VScanDemonStarter it puts entries into its (different) log file, the VScanDemon log file gets created, but no entries. I can see it is executing because some files get moved from one directory to another. Just no Log entries.
the config looks like
<root>
<level value="INFO" />
</root>
<appender name="LogFileAppender" type="log4net.Appender.RollingFileAppender" >
<param name="File" value="log/vscandemonstarter.log" />
<param name="AppendToFile" value="true" />
<rollingStyle value="Size" />
<maxSizeRollBackups value="10" />
<maximumFileSize value="10MB" />
<staticLogFileName value="true" />
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%-5p %d{yyyy-MM-dd hh:mm:ss} - %m%n" />
</layout>
</appender>
<appender name="vsdemonlogfileappender" type="log4net.Appender.RollingFileAppender" >
<param name="File" value="log/vscandemon.log" />
<param name="AppendToFile" value="true" />
<rollingStyle value="Size" />
<maxSizeRollBackups value="10" />
<maximumFileSize value="10MB" />
<staticLogFileName value="true" />
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%-5p %d{yyyy-MM-dd hh:mm:ss} - %m%n" />
</layout>
</appender>
and the code bodies set up and call the bodies with.
VScanDemonStarter:
top of module:
Private ReadOnly log As ILog = log4net.LogManager.GetLogger("default")
top of main:
log4net.Config.XmlConfigurator.Configure()
example calls:
If log.IsInfoEnabled Then log.Info("VScanDemonStarter:Main: ----called----")
VBScanDemon:
top of module:
Private ReadOnly log As ILog = log4net.LogManager.GetLogger("VSDemonLogger")
top of main:
log4net.Config.XmlConfigurator.Configure()
VBScanDemon:
If log.IsInfoEnabled Then log.Info("VScanDemon:Main: ----called----")
I don't get any log entries from VScanDemon.
Sorry left out the top of the configuration
<log4net debug="true">
<logger name="default">
<level value="INFO"/>
<appender-ref ref="LogFileAppender" />
</logger>
<logger name="VSDemonLogger">
<level value="INFO"/>
<appender-ref ref="vsdemonlogfileappender" />
</logger>
I have one app.config but two projects in the same directory using it. They generate seperate configs from that one source .exe.config
I looked at the console output from VScanDemon and it looks like it is picking up the configuration with no issues. But still an empty log. I don't know if I need to add a flush or something.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否为两个模块使用相同的 log4net 配置?
如果不是,它们在运行时真的不同吗?
我认为“默认”应该返回根记录器,而“VSDemonLogger”应该返回另一个记录器,但该记录器不包含在您发布的配置中。
编辑:
AFAIK 配置中的所有记录器都将被“创建”,这会导致为您的 VSDemonLogger 和 VScanDemonStarter 生成日志文件,即使您不使用它们。
您在配置中使用相对路径,如果您从 VScanDemonStarter 调用 VSDemonLogger,它们对 VSDemonLogger 仍然有效吗?
Are you useing the same log4net configuration for both modules?
If not, are they really different at runtime?
I think "default" should return the Root-logger and "VSDemonLogger" the other one but that one is not included in your posted configuration.
EDIT:
AFAIK all logger in the configuration will be "created", which results in the generated log files for your VSDemonLogger and VScanDemonStarter even if you do not use them.
You are using relativ pathes in the configuration, are they still valid for VSDemonLogger if you call it from VScanDemonStarter?