asp.net - log4net 在类库中不起作用
问题描述
I want to implement logging function into a class library, which is itself referenced in a webapplication. I tried to add app.config and did everything needed, but its not logging any message, log4net simply does nothing.
Here is my app.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
</configSections>
<log4net debug="true">
<appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
<file value="D:\StagingPortal2012\Communicationlogs\TestProjlog4net.txt" />
<appendToFile value="true" />
<rollingStyle value="Size" />
<maxSizeRollBackups value="10" />
<maximumFileSize value="20MB" />
<staticLogFileName value="true" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%newline%-5p %d %-22.22c{1} %-18.18M - %m%n" />
</layout>
</appender>
<root>
<appender-ref ref="RollingLogFileAppender" />
<level value="DEBUG"></level>
</root>
</log4net>
<appSettings>
<add key="log4net.Internal.Debug" value="true" />
</appSettings>
</configuration>
And Assembly.Info.cs
[assembly: log4net.Config.XmlConfigurator(ConfigFile = "App.config")]
还有 Communicator.cs(我用 log4net 写日志的地方)
私有静态只读 ILog Log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
解决方案
推荐阅读
- javascript - 将带有插槽的 shadow dom 的子级移出 Web 组件
- pandoc - 有没有办法让一个部分链接回 pandoc 中的目录?
- shopify - 如何编辑允许 shopify 用户标签
- javascript - 通过父 websocket 更新数以千计的反应子级
- postgresql - Kotlin 公开访问分区数据库
- rust - 在 GTK4 中制作一个可点击的框
- pandas - 仅将可用日期值添加到每月数据框
- json - Thingsboard:读取 MQTT 时间戳时出现 JSON 解析错误
- java - 无法将密钥()发送到输入文本字段
- javascript - 带有三个 JS 的 Angular - 画布呈现在错误的位置