使用log4net,在win7上可以正常使用,在xp电脑上可以生成access数据库,但是无法写数据到mdb文件,即mdb始终是空白的

排除了程序原因,怀疑是xp缺少什么dll之类的

偶然查到log4net的调试方法:

第1步:

(1)如果是配置在app.confing等confing文件中,在appSettings节点中增加名称为“log4net.Internal.Debug”的节点,并确保值为“true"

 <configuration>
<appSettings>
<add key="log4net.Internal.Debug" value="true"/>
</appSettings>
</configuration>

(2)如果配置在自定义的confing中,通过代码自定义调用,则直接在log4net节点增加debug="true"

<configuration>
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
</configSections> <log4net debug="true">
<appender name="AllRollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
......
</appender>
</log4net>
</configuration>

第2步:在app.config文件<configuration>节点内增加如下节点

<system.diagnostics>
<trace autoflush="true">
<listeners>
<add
name="textWriterTraceListener"
type="System.Diagnostics.TextWriterTraceListener"
initializeData="C:\tmp\log4net.txt" />
</listeners>
</trace>
</system.diagnostics>

注意:文件夹 C:\tmp 必须存在,否则无法创建文件

另外我在自定义并且加了watch的的config文件中加这段无效,不清楚是什么原因

或者用代码添加

System.Diagnostics.Trace.Listeners.Clear();
System.Diagnostics.Trace.Listeners.Add(
new System.Diagnostics.TextWriterTraceListener("C\tmp\log4net.txt"));

加入了log4net的内部调试功能后,再运行程序调用log4net写日志时,会在C:\tmp\log4net.txt文件中显示出如下错误信息:

log4net:ERROR [AdoNetAppender] ErrorCode: GenericFailure. Failed in DoAppend
System.TypeLoadException: Could not load type 'System.Security.Claims.ClaimsIdentity' from assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
at log4net.Core.LoggingEvent.get_UserName()
at log4net.Core.LoggingEvent.FixVolatileData(FixFlags flags)
at log4net.Appender.BufferingAppenderSkeleton.Append(LoggingEvent loggingEvent)
at log4net.Appender.AppenderSkeleton.DoAppend(LoggingEvent loggingEvent)

简单的理解是找不到类System.Security.Claims.ClaimsIdentity,查了下msdn,这个类属于.net 4.5

在网上搜了许久没找到解决方法,都大同小异,跟log4net官方说法类似 让别用xp,或者安装.net framework 4.5

但是现在国内很多地方为了节约成本等原因还是在用xp,而xp最高只能安装.net 4.0,显然无法解决

我试过安装.net framework 4.0的补丁,KB2468871、KB2861188、KB2789642、KB2898855、KB2901110,结果无效

试过360修复所有漏洞,按推荐的打了所有补丁,也不行

通过网上的帖子了解到,问题引入的原因可能是,我使用了在.net 4.5的环境中生成的log4net.dll

于是顺着这个思路,我最终也找到解决方案:

在官网下载源码log4net-2.0.8-src.zip,解压后用vs2010打开log4net-2.0.8-src\log4net-2.0.8\src下的log4net.vs2010.sln

源码下有两个项目,直接生成解决方案会报错,发现是 log4net.Tests.vs2010下的nunit.framework引用丢失了

直接在log4net.Tests.vs2010上右键,卸载项目,再重新生成就好了

最后将log4net-2.0.8-src\log4net-2.0.8\build\bin\net\4.0\debug目录下重新生成的dll引入到我们的工程就好了

简单测试了一下可以使用,问题解决。附上文件log4net.dll (2.0.8   .net framework 4.0)

log4net报错Could not load type 'System.Security.Claims.ClaimsIdentity'的更多相关文章

  1. Unable to find a constructor to use for type System.Security.Claims.Claim. A class should either have a default constructor

    Newtonsoft.Json DeserializeObject 反序列化  IdentityServer4.Models Cliecnt 错误: Newtonsoft.Json.JsonSeria ...

  2. Atom打开报错:"Cannot load the system dictionary for zh-CN"

    1. 问题描述 最近每次使用atom打开文件,总是报错"Cannot load the system dictionary for zh-CN" 2. 解决方法 File --&g ...

  3. Could not load type 'System.Reflection.AssemblySignatureKeyAttribute' from assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c

    错误: Could not load type 'System.Reflection.AssemblySignatureKeyAttribute' from assembly 'mscorlib, V ...

  4. 备库搭建后,进入备库报错psql: FATAL: the database system is starting up

        备库搭建后,进入备库报错psql: FATAL:  the database system is starting up  原因:备库配置文件没有hot_standby = on   mast ...

  5. 报错: Access restriction: The type JPEGImageEncoder is not accessible due to restriction on required library

    报错: Access restriction:The type JPEGCodec is not accessible due to restriction on required library C ...

  6. junit单元测试报错Failed to load ApplicationContext,但是项目发布到tomcat浏览器访问没问题

    junit单元测试报错Failed to load ApplicationContext,但是项目发布到tomcat浏览器访问没问题,说明代码是没问题的,配置也没问题.开始时怀疑是我使用junit版本 ...

  7. Linux mount挂载磁盘报错 mount: wrong fs type, bad option, bad superblock on /dev/vdb

    Linux mount挂载磁盘报错  mount: wrong fs type, bad option, bad superblock on /dev/vdb Linux挂载磁盘报如下错误: moun ...

  8. Could not load type 'System.ServiceModel.Activation.HttpModule' from assembly 'System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'

    Could not load type 'System.ServiceModel.Activation.HttpModule' from assembly 'System.ServiceModel, ...

  9. Could not load type 'System.Runtime.CompilerServices.ExtensionAttribute'

    [TypeLoadException: Could not load type 'System.Runtime.CompilerServices.ExtensionAttribute' from as ...

随机推荐

  1. java_时间戳与Date_相互转化

    [转自:http://blog.csdn.net/heng615975867/article/details/36016617] 1.时间戳的定义 时间戳是指文件属性里的创建.修改.访问时间. 数字时 ...

  2. loj2275 「JXOI2017」颜色

    枚举右端点,然后看左端点合法情况. 先预处理每个颜色 \(i\) 的最大出现位置 \(max_i\) 和最小出现位置 \(min_i\).对于枚举右端点在一个位置 \(i\),凡是 \(max_k & ...

  3. 设计模式之工厂模式 Factory实现

    simpleFactory //car接口 public interface Car { void run(); } //两个实现类 public class Audi implements Car{ ...

  4. operator的各种问题

    a+b = a^b + (a&b)<<1 用位运算实现两数相加 int Add(int a,int b) { return b?Add(a^b,(a&b)<<1 ...

  5. queue 类

    一:普通队列 1.队列特征:先进先出,它只允许在一端(队尾)进行插入元素操作,在另一端(队头)进行删除元素操作 2. 存取类函数 front():用来取出queue中的队头元素,对应于front()函 ...

  6. 九度oj 题目1184:二叉树遍历

    题目描述: 编一个程序,读入用户输入的一串先序遍历字符串,根据此字符串建立一个二叉树(以指针方式存储). 例如如下的先序遍历字符串:ABC##DE#G##F###其中“#”表示的是空格,空格字符代表空 ...

  7. 《Spark Python API 官方文档中文版》 之 pyspark.sql (四)

    摘要:在Spark开发中,由于需要用Python实现,发现API与Scala的略有不同,而Python API的中文资料相对很少.每次去查英文版API的说明相对比较慢,还是中文版比较容易get到所需, ...

  8. 【Luogu】P3809后缀排序(后缀数组模板)

    题目链接 今天终于学会了后缀数组模板qwq 不过只会模板emmmm 首先我们有一本蓝书emmmmmm 然后看到蓝书221页代码之后我就看不懂了 于是请出rqy rqy: 一开始那是个对单个字符排序的操 ...

  9. mysql经验总结

    1. 连接mysql遇到 Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2),mysql没有正常启动 $ ...

  10. 《快速开发》通过Maven创建WebService项目Hello World!

    有多快? 整个过程3分钟.不用下载jar包,不用一步一步创建Web Project... 你需要的就是在Maven库里选一个archetype,然后一路Next~ 先看结果: 准备好了吗?我们起飞: ...