使用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. css图像处理与动画

    先讨论几个css 问题 1,css 清除浮动的方法 2,css 居中 3,多行省略号 4,小布局技巧 2D 动画功能属性兼容性:transform.transition.animation trans ...

  2. 一个TensorFlow例子

    一个TensorFlow的例子 import tensorflow as tf x = tf.constant(1.0, name='input') w = tf.Variable(0.8, name ...

  3. PHP下mysql驱动概述

    Overview of the MySQL PHP drivers 什么是API? 一 个应用程序接口(Application Programming Interface的缩写),定义了类,方法,函数 ...

  4. Springmvc web项目初始化

    Web容器首先会读取项目中的web.xml配置文件中的两个节点:<context-param>与<listener> Web容器创建ServletContext对象即Servl ...

  5. 基于2.9.6vue-cli初始化webpack工程

    前天做了组内的分享 讲了些webpack的东西 整个流程以及build文件夹内webpack相关的一些js所有的代码 每行代码什么意思 有什么作用 都做了很详细的标明. webpack是3.6的 今天 ...

  6. 【Luogu】P3389高斯消元模板(矩阵高斯消元)

    题目链接 高斯消元其实是个大模拟qwq 所以就着代码食用 首先我们读入 ;i<=n;++i) ;j<=n+;++j) scanf("%lf",&s[i][j]) ...

  7. Android逆向之旅---动态方式破解apk进阶篇(IDA调试so源码)

    Android逆向之旅---动态方式破解apk进阶篇(IDA调试so源码) 来源 https://blog.csdn.net/jiangwei0910410003/article/details/51 ...

  8. 刷题总结——advanced fruits(hud1503)

    题目: The company "21st Century Fruits" has specialized in creating new sorts of fruits by t ...

  9. 修改Tomcat HTTP端口号(8080→8088)Eclipse

    1.如果不用Eclipse,修改Tomcat的端口号,可以参考这篇: https://jingyan.baidu.com/article/adc815139b12def722bf7377.html t ...

  10. 【bzoj2301】[HAOI2011]Problem b 莫比乌斯反演

    Description 对于给出的n个询问,每次求有多少个数对(x,y),满足a≤x≤b,c≤y≤d,且gcd(x,y) = k,gcd(x,y)函数为x和y的最大公约数. Input 第一行一个整数 ...