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

相关文章
|
6月前
|
开发框架 .NET 测试技术
.NET Core 日志记录程序和常用日志记录框架
本文主要内容为.NET Core的日志记录程序和常使用的日志记录框架的简单使用 首先,打开VS2019新建一个ASP.NET Core Web Api项目,项目创建好后会有一个集成好的天气预报的类和控制器,接下来,我们的方法就在天气控制器里完成。
51 0
|
6月前
|
Java 程序员 C#
C#日志系统 Log4net使用总结
C#日志系统 Log4net使用总结
43 0
|
10月前
|
开发框架 监控 前端开发
ASP.NET Core MVC 从入门到精通之日志管理
ASP.NET Core MVC 从入门到精通之日志管理
75 0
|
10月前
|
C++
VS-2019-.NET-C#使用log4net打日志,程序日志记录
VS-2019-.NET-C#使用log4net打日志,程序日志记录
108 0
|
10月前
|
C#
VS2019 C# .NET 如何实现打日志功能
VS2019 C# .NET 如何实现打日志功能
120 0
|
11月前
|
程序员 数据库
日志记录:Log4net
Log4net是一个帮助程序员将日志信息输出到各种目标(控制台、文件、数据库等)的工具。日志是程序的黑匣子,可以通过日志查看系统的运行过程,从而发现系统的问题。日志的作用:将运行过程的步骤、成功失败记录下来,将关键性的数据记录下来,进而分析系统问题所在。因为对于网站来说,不能把异常信息显示给用户,异常信息只能记录到日志。网站出问题后,开发人员查看日志就知道问题所在。
|
Java Maven
严重: Error configuring application listener of class org.springframework.web.util.Log4jConfigListener
严重: Error configuring application listener of class org.springframework.web.util.Log4jConfigListener
110 0
严重: Error configuring application listener of class org.springframework.web.util.Log4jConfigListener
|
JSON 监控 数据可视化
【.NET 6+Loki+Grafana】实现轻量级日志可视化服务功能
日志功能是几乎所有程序或系统都必备的一个功能。该文章通过使用Loki+Grafana来实现日志记录与可视化查询,欢迎围观。
263 0
【.NET 6+Loki+Grafana】实现轻量级日志可视化服务功能
|
消息中间件 存储 自然语言处理
十八、.net core(.NET 6)搭建ElasticSearch(ES)系列之使用Logstash通过Rabbitmq接收Serilog日志到ES
使用Logstash通过Rabbitmq接收Serilog日志到ES首先,要部署logstash 为了与前面的ElasticSearch版本保持一致,此处Logstash下载的版本也是7.13.1, 下载地址:https://artifacts.elastic.co/downloads/logstash/logstash-7.13.1-windows-x86_64.zip
356 0
十八、.net core(.NET 6)搭建ElasticSearch(ES)系列之使用Logstash通过Rabbitmq接收Serilog日志到ES
.NET 6新东西--高性能日志
.NET 6新东西--高性能日志
421 0