为什么log4net的1.2.10要求的System.Web?log4net、Web、System

2023-09-04 00:41:18 作者:朋友总有一个是真心的

我正在写一个控制台应用程序面向.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

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