使用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. git 强制回到以前版本

    git reset dfd3e36a641340a0b86f811df869c4375fabeff2 --hard

  2. Linux内存cache/buffer剖析

    查询linux系统中空闲内存/内存使用状态查看/剩余内存查看 如何计算内存的使用量及空闲量 物理已用内存 = 实际已用内存 - 缓冲 - 缓存              =  24752  - 283 ...

  3. python + selenium - 自动化环境搭建

    1. 安装python (1)下载地址:https://www.python.org/downloads/windows/ (2)安装方式:默认安装即可 (3)环境变量配置:打开[系统属性]-[环境变 ...

  4. 二进制<2>

    位运算简介及实用技巧(二):进阶篇(1) =====   真正强的东西来了!   ===== 二进制中的1有奇数个还是偶数个    我们可以用下面的代码来计算一个32位整数的二进制中1的个数的奇偶性, ...

  5. [OJ#63]树句节够提

    [OJ#63]树句节够提 试题描述 给定一棵节点数为 N 的有根树,其中 1 号点是根节点,除此之外第 i 个节点的父亲为 fi.每个节点有一个权值 Ai,所有边权均为 1. 给定 Q 个询问,每个询 ...

  6. docker (centOS 7) 使用笔记2 - 使用nfs作为volume

    本次测试的服务器2台,服务器#1(centos7)最为docker容器所在的host,服务器#2(centos6)提供NFS服务 1. #2上配置NFS服务 (1) 安装nfs软件包 yum -y i ...

  7. 《如何成为一位大家愿意追随的Leader》读后感

    今天看了左耳朵耗子老师的文章<如何成为一位大家愿意追随的Leader>深有感触.每一行字都往心里说,文章里说到Leader和Boss的不同点在于,Leader是大家跟我一起上,而Boss则 ...

  8. IPython:一种交互式计算和开发环境

    一 键盘快捷键 - Ctrl-P    或上箭头键 后向搜索命令历史中以当前输入的文本开头的命令 - Ctrl-N   或下箭头键 前向搜索命令历史中以当前输入的文本开头的命令 - Ctrl-R    ...

  9. 介绍一款移动端滚动加载的插件---dropload

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  10. ubuntu16.04下安装wine1.8.2

    如果是amd64则需要执行这个: sudo dpkg --add-architecture i386 1 1 添加wine最新的源 sudo add-apt-repository ppa:wine/w ...