为什么log4net的1.2.10要求的System.Web? [英] Why does log4net 1.2.10 require System.Web?

查看:306
本文介绍了为什么log4net的1.2.10要求的System.Web?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写一个控制台应用程序面向.NET Framework 4的客户端配置文件此code。

I'm writing this code in a Console Application targeting the .NET Framework 4 Client Profile.

this.container.AddFacility<LoggingFacility>(
  f => f.LogUsing(LoggerImplementation.Log4net));

当它运行时,出现一个类型转换错误。

When it runs, it fails with a type conversion error.

无法从转换'Castle.Services.Logging.Log4netIntegration.Log4netFactory,Castle.Services.Logging.Log4netIntegration,Version=2.5.1.0,   文化=中性公钥= 407dd0808d44fbdc'   以System.Type的 - 也许类型不能   找到

Could not convert from 'Castle.Services.Logging.Log4netIntegration.Log4netFactory,Castle.Services.Logging.Log4netIntegration,Version=2.5.1.0, Culture=neutral,PublicKeyToken=407dd0808d44fbdc' to System.Type - Maybe type could not be found

这是因为Castle.Services.Logging.log4netIntegration组件将不会复制到输出文件夹。作为一个仅运行时依赖,这不破坏构建。

This is because the Castle.Services.Logging.log4netIntegration assembly is not copied to the output folder. As an runtime-only dependency, this doesn't break the build.

综观生成过程中,我发现,这是不复制log4net的或城堡基​​金大会,因为他们依赖的System.Web这是不是在客户端配置文件可用。更改为标准配置意味着,这种依赖性可用和设施可以加入。

Looking at the build process, I found that it was not copying log4net or the Castle facility assembly because they depend on System.Web which is not available in the Client Profile. Changing to the standard profile means that this dependency is available and the facility can be added.

为什么这样做?它使我不是针对设计中的控制台应用程序的客户端配置文件被用作服务器上的计划任务有什么区别?

Why is this be done? What difference does it make that I am not targeting the client profile in a console application designed to be used as a scheduled task on a server?

推荐答案

一些附加目的地的依赖的System.Web如AspNetTraceAppender。提供给开发者唯一的选择将是分裂出来组成部分,不依赖于系统的核心为独立的组件,但将打破log4net的美景,因为它是如此的简单易用。此外,在写作的log4net的时候,我不相信他们是这样一个东西作为一个客户端配置文件。

Some of the appenders depend on System.Web such as the AspNetTraceAppender. The only other option available to the developers would have been to split out components that don't depend on the System core into separate assemblies but that would have broken the beauty of log4net in that it is so simple to use. Additionally at the time of writing log4net I don't believe their was such a thing as a Client Profile.

由于log4net的是开源的,没有什么阻止你从网上下载源和移除有问题的类和创建自己的客户端配置文件为中心的log4net组件。

Since log4net is open source there is nothing stopping you from downloading the source and removing the offending classes and creating your own Client Profile centric log4net assembly.

HTTP: //www.the$c$cking.co.uk/2010/08/making-log4net-work-with-net-client.html

  1. 下载log4net的源
  2. 开启和放大器;使用升级解决方案的Visual Studio 2010
  3. 删除的System.Web项目引用
  4. 从项目中排除追加程序\ AspNetTraceAppender.cs类
  5. 添加引用System.Configuration
  6. 在导航到项目 - > log4net的性能,并选择应用程序标签
  7. 更改目标框架.NET Framework 3.5的客户端配置文件
  8. 选择生成选项卡,并配置更改为调试
  9. 在条件编译符号更改为NET; NET_1_0; NET_2_0;
  10. 更改配置为发布
  11. 在条件编译符号更改为强;网; NET_1_0; NET_2_0;
  12. 编辑的AssemblyInfo.cs中类和更新AssemblyKeyFile中的属性与一个有效的强键
  13. 编译发布模式项目,并分发新组件
  1. Download the log4net source
  2. Open & upgrade the solution using Visual Studio 2010
  3. Remove the System.Web project reference
  4. Exclude Appender\AspNetTraceAppender.cs class from the project
  5. Add a reference to System.Configuration
  6. Navigate to Project -> log4net properties, and select the application tab
  7. Change the target framework to .NET Framework 3.5 Client Profile
  8. Select the Build tab, and change the configuration to Debug
  9. Under Conditional compilation symbols change this to NET;NET_1_0;NET_2_0;
  10. Change the configuration to Release
  11. Under Conditional compilation symbols change this to STRONG;NET;NET_1_0;NET_2_0;
  12. Edit the AssemblyInfo.cs class and update the AssemblyKeyFile attribute with a valid strong key
  13. Compile the project in Release mode and distribute the new assembly

这篇关于为什么log4net的1.2.10要求的System.Web?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆