使用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. C++异常安全的赋值运算符重载 【微软面试100题 第五十五题】

    题目要求: 类CMyString的声明如下: class CMyString { public: CMyString(char *pData=NULL); CMyString(const CMyStr ...

  2. Leetcode21--->Merge Two Sorted Lists(合并两个排序的单链表)

    题目: 给出两个排序的单链表,合并两个单链表,返回合并后的结果: 解题思路: 解法还是很简单的,但是需要注意以下几点: 1.  如果两个链表都空,则返回null; 2.  如果链表1空,则返回链表2的 ...

  3. 对于运用git将本地文件上传到coding总结

    首先需要在你的本地磁盘下建立一个目录,并且进入该目录. 前几次课程上有讲到&的用法,&&表示并且. 命令 ”makir 文件名 && cd 文件名”,cd指进入 ...

  4. OpenCV For Java环境搭建与功能演示

    http://blog.csdn.net/jia20003/article/details/68944486

  5. Django notes I: collection of links to the Django document

    Links to the Django documents: the Django template language automatically generated context variable ...

  6. mybatis学习(五)——增删改查及自增主键的获取

    一.mybatis的增删改查 1.修改hotelMapper接口 package com.pjf.mybatis.dao; import com.pjf.mybatis.po.Hotel; publi ...

  7. 【NOI2017】游戏

    好久没写 $2-sat$ 了……(话说这东西哪里还考过) 题意 有 $3$ 种赛车 $A,B,C$ 和 $4$ 种赛道 $a,b,c,x$,赛车 $A$ 不适用于赛道 $a$,赛车 $B$ 不适用于赛 ...

  8. CentOS7开启docker远程访问

    在 CentOS 中没有 /etc/default/docker,另外在 CentOS7 中也没有找到 /etc/sysconfig/docker这个配置文件. 在 /usr/lib/systemd/ ...

  9. javascript事件捕获机制,dom tree

    $(document,"a").on("click",function(){alert(2);return false;}); $("<a> ...

  10. JS函数(自调函数)与闭包【高级函数】

    JavaScript:BOM(浏览器对象)+DOM(文档对象)+ECMAScript javascript面向对象: * 概述: * 发展: * 互联网发展对浏览器页面性能或效果要求越来越高,HTML ...