Configuring log4net with VS2010 and .Net 4.0

简介:

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,如需转载请自行联系原作者

相关文章
|
XML 开发框架 .NET
ASP.NET COR3.1 集成日志插件NLog
ASP.NET COR3.1 集成日志插件NLog
167 0
|
SQL 程序员
分享一个 .NET 通过监听器拦截 EF 消息写日志的详细例子
分享一个 .NET 通过监听器拦截 EF 消息写日志的详细例子
105 0
|
11月前
|
JSON 安全 API
.net 自定义日志类
在.NET中,创建自定义日志类有助于更好地管理日志信息。示例展示了如何创建、配置和使用日志记录功能,包括写入日志文件、设置日志级别、格式化消息等。注意事项涵盖时间戳、日志级别、JSON序列化、线程安全、日志格式、文件处理及示例使用。请根据需求调整代码。
167 13
|
开发框架 .NET Docker
【Azure 应用服务】App Service .NET Core项目在Program.cs中自定义添加的logger.LogInformation,部署到App Service上后日志不显示Log Stream中的问题
【Azure 应用服务】App Service .NET Core项目在Program.cs中自定义添加的logger.LogInformation,部署到App Service上后日志不显示Log Stream中的问题
190 1
|
开发框架 .NET 测试技术
.NET Core 日志记录程序和常用日志记录框架
本文主要内容为.NET Core的日志记录程序和常使用的日志记录框架的简单使用 首先,打开VS2019新建一个ASP.NET Core Web Api项目,项目创建好后会有一个集成好的天气预报的类和控制器,接下来,我们的方法就在天气控制器里完成。
233 0
分享一份 .NET Core 简单的自带日志系统配置,平时做一些测试或个人代码研究,用它就可以了
分享一份 .NET Core 简单的自带日志系统配置,平时做一些测试或个人代码研究,用它就可以了
217 0
|
开发框架 .NET API
如何在 ASP.NET Core Web Api 项目中应用 NLog 写日志?
如何在 ASP.NET Core Web Api 项目中应用 NLog 写日志?
608 0
|
监控 程序员 数据库
分享一个 .NET Core Console 项目中应用 NLog 写日志的详细例子
分享一个 .NET Core Console 项目中应用 NLog 写日志的详细例子
248 0
|
SQL
.Net Core EF 日志打印 SQL 语句
.Net Core EF 日志打印 SQL 语句
285 0
|
Java 程序员 C#
C#日志系统 Log4net使用总结
C#日志系统 Log4net使用总结
427 0