Configuring log4net with VS2010 and .Net 4.0

本文介绍如何在Visual Studio 2010和.NET 4.0环境下配置log4net的日志组件。主要包括设置条件编译符号、确保log4net具有完整的.NET访问权限、调整log4net的安全级别等步骤。

Configuring log4net with VS2010 and .Net 4.0

After spending a few hours this morning trying to get log4net working with a project, I decided to share my findings.   I chased a lot of dead-ends for what wound up being a fairly simple solution.  Here is a quick article to save both myself, and maybe you, some time in the future.

Get Log4Net

Go to http://logging.apache.org/log4net/ and get the latest version.    Add the project file to your solution.   Then right-click that project, choose the build tab and…

Step 1: Set the log4net conditional compilation symbols replacing NET_1_0 with NET_4_0.

Log4Net Requires Full .Net Access

That means you cannot use “client profile”.  log4net was originally written to log web services.  As such it expects to have a lot of server-side classes available, even though most of those classes are never instantiated.

Step 2: Build  Your Application & The Log4Net component under .Net 4.0, not .Net 4.0 Client Profile

Make Log4Net Less Secure

The .Net 4.0 assemblies are more secure by default.  You need to override this.   As I’m not a .Net development guru I’m not really certain what the differences mean, but Google is your friend (and mine) here, so if you are concerned (and you should be before launching a public app) then search the Internet to find out what this mean. In the meantime…

Step 3: Make log4net assembly less secure, add 
[assembly: System.Security.SecurityRules(System.Security.SecurityRuleSet.Level1)] 
to the log4net AssemblyInfo.cs file.

Done.

That’s it, the first steps for getting a log4net component into your application.   Now you can follow some of the development & deployment document on the Apache site:

http://logging.apache.org/log4net/release/manual/configuration.html

 

编译好的for .net 4.0 的log4net库文件下载:

log4net for .net 4.0   : http://files.cnblogs.com/sgsoft/log4Net_4.0.zip


本文转自海天一鸥博客园博客,原文链接:http://www.cnblogs.com/sgsoft/archive/2011/08/02/2125508.html,如需转载请自行联系原作者

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值