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 : https://files.cnblogs.com/sgsoft/log4Net_4.0.zip
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 字符编码:从基础到乱码解决