将log4net 1.2.11添加到项目中,使用日志功能。
网上很多,下面简要说说他的步骤:
1.下载log4net,现在的最新版是1.2.11
2.引用log4net.dll
3.在AssemblyInfo.cs文件中添加
[assembly: log4net.Config.XmlConfigurator(Watch = true)]
4.添加app.config(WinForm)或者在web.config当然也可以指定其他的文件名。但是在上一步添加ConfigFile属性即可。
5.编辑app.config,整理正确的如下:注意编辑完app.config文件关闭然后编译,否则可能出现如题所示的message.
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
</configSections>
<log4net>
<root>
<level value="ALL" />
<appender-ref ref="SysAppender" />
</root>
<appender name="SysAppender" type="log4net.Appender.RollingFileAppender">
<param name="File" value="Log\logs" />
<param name="AppendToFile" value="true" />
<param name="MaxSizeRollBackups" value="30" />
<param name="MaximumFileSize" value="100MB" />
<param name="RollingMode" value="Date" />
<param name="DatePattern" value="'_'yyyy-MM-dd'.txt'" />
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%date [%thread] %-5level %logger [%method] %L [%exception] - %message%newline" />
</layout>
</appender>
</log4net>
</configuration>
6.在程序中使用
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
log.Debug("test");即可。
刚开始出现如题所示的错误,我也找了很长时间。并且重新创建个新项目来测试。知道最后还是出现这个信息。当然了,假如你关闭app.config就不出现了。
假如配置正确,运行没有出现错误提示都应该出现日志。
只要调试的时候log不等于null。其他的就应该是app.config设置错误。
我曾经在C++用过有DailyRollingFileAppender,而.net中没有。不知道是1.2.11给删除了还是就没有。旧版本没用过。
分享到:
相关推荐
Could not resolve dependencies for project org.apache.flink:flink-avro-confluent-registry:jar:1.15.3: Could not find artifact io.confluent:kafka-schema-registry-client:jar:6.2.2 in maven 安装本地...
- schema_reference.4: Failed to read schema document 'http://code.alibabatech.com/schema/dubbo/dubbo.xsd', because 1) could not find the document; 2) the document could not be read; 3) the root ...
MySQL中information_schema是什么
- schema_reference.4: Failed to read schema document 'http://code.alibabatech.com/schema/dubbo/dubbo.xsd', because 1) could not find the document; 2) the document could not be read; 3) the root ...
MySQL中information_schema系统表
- schema_reference.4: Failed to read schema document 'http://code.alibabatech.com/schema/dubbo/dubbo.xsd', because 1) could not find the document; 2) the document could not be read; 3) the root ...
在myeclipse中使用dubbo时报一下的错误信息:Multiple annotations found ... because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not 的解决文件
•For each department, find the maximum salary of instructors in that department. You may assume that every department has at least one instructor. •Find the lowest, across all departments, of the ...
dubbo配置xml文件报错“Multiple annotations found at this line: ... 2) the document could not be read; 3) the root element of the document is not <xsd:schema>.” dubbo.xsd文件下载
star schema dimensional modeling
because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not 解决方案: 下载一个dubbo.xsd文件 windows->preferrence->xml->xmlcatalog add->...
The Little MongoDB Schema Design Book, covers the fundamentals off Schema design with MongoDB, as well as several useful Schema design patters for your applications. I wrote this book to be a helpful...
json-schema, ruby JSON架构验证程序 ruby JSON模式验证器这个库旨在为 ruby 提供一个接口,用于针对符合 JSON模式草案 4的JSON模式验证JSON对象。 Legacy Legacy Schema Schema Draft 和 JSON模式草
DataBase Schema For a Cake Shop
The necessary information for schema design is given in the.Universe of Discourse (UoD).This assignment can be completed as a group. The maximum size of a group is three people.Each group is allowed ...
本文介绍了information_schema数据库的三张重要的表"schemata"、“tables”和“columns”在SQL注入中的应用思路。
typescript-json-schema, 从你的Typescript源生成json模式 typescript-json-schema 从你的Typescript源生成json模式。特性编译你的打字程序以获取完整的类型信息。转换必需的属性,扩展,注释关键字,属性初始值设定...
3.在这边点击 Executables,在Export Dump:和Import Dump:中分别输入Oracle安装路径\product\10.1.0\db_3\BIN\expdp.exe,Oracle安装路径\oracle\product\10.1.0\db_3\BIN\impdp.exe,点 OK 4.进入 Database|Export|...
THE SOFTWARE LICENSE AND LIMITED WARRANTY FOR THE ACCOMPANYING PRODUCT ARE SET FORTH IN THE INFORMATION PACKETTHAT SHIPPED WITH THE PRODUCT AND ARE INCORPORATED HEREIN BY THIS REFERENCE. IF YOU ARE ...