- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
所以我已经尝试了我能找到的一切让这两个一起玩。
我已经安装了 nuget 包 Common.Logging.NLog20,
我的配置看起来像:
<configSections>
<sectionGroup name="common">
<section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging" />
</sectionGroup>
<section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog20" />
</configSections>
<common>
<logging>
<factoryAdapter type="Common.Logging.NLog.NLogLoggerFactoryAdapter, Common.Logging.NLog20">
<arg key="configType" value="INLINE" />
</factoryAdapter>
</logging>
</common>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="NLog" publicKeyToken="5120e14c03d0593c" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.1.0.0" newVersion="2.1.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Common.Logging" publicKeyToken="af08829b84f0328e" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
internalLogFile="nlog.ERRORS.txt" internalLogLevel="Error" >
<!--
See http://nlog-project.org/wiki/Configuration_file
for information on customizing logging rules and outputs.
-->
<targets>
<!-- add your targets here -->
<target xsi:type="File" name="log" keepFileOpen="true"
fileName="${basedir}/log_${date:format=yyyyMMdd}.txt"
layout="${longdate} ${level:uppercase=true:padding=5} - ${logger:shortName=true} - ${message} ${exception:format=tostring}" />
<target name="log_errors_memory" xsi:type="Memory"
layout="${longdate} ${level:uppercase=true:padding=5} - ${logger:shortName=true} - ${message} ${exception:format=tostring}" />
<target name="log_all_memory" xsi:type="Memory"
layout="${longdate} ${level:uppercase=true:padding=5} - ${logger:shortName=true} - ${message} ${exception:format=tostring}" />
</targets>
<rules>
<!-- add your logging rules here -->
<logger name="*" minlevel="Trace" writeTo="log" />
<logger name="*" minlevel="Trace" writeTo="log_all_memory" />
<logger name="*" minlevel="Error" writeTo="log_errors_memory" />
</rules>
</nlog>
{"Failed obtaining configuration for Common.Logging from configuration section 'common/logging'."}
Inner Exception:
{"An error occurred creating the configuration section handler for common/logging: Type Common.Logging.NLog.NLogLoggerFactoryAdapter, Common.Logging.NLog20, Version=2.2.0.0, Culture=neutral, PublicKeyToken=af08829b84f0328e does not implement Common.Logging.ILoggerFactoryAdapter\r\nParameter name: factoryAdapterType\r\nActual value was Common.Logging.NLog.NLogLoggerFactoryAdapter. (D:\\Development\\Code\\DotNet\\vs2013\\exe\\CommandLine\\PSVImporter\\FidessaPSVImport.Test\\bin\\Debug\\FidessaPSVImport.Test.dll.config line 17)"}
最佳答案
这是一种卑鄙的方法,可以为您节省很多麻烦。 Common.Logging.NLogXX 附带的适配器 NLogLoggerFactoryAdapter 没有什么特别之处,只是为您设置了 NLog。这是大多数人可以自己做的事情。
换句话说,如果你已经设置了 NLog,你需要做的就是将 Common.Logging 连接到 NLog。这可以通过编写一个简单的工厂来完成,该工厂将创建如下所示的 NLog Loggers:
public class MyAdapter : AbstractCachingLoggerFactoryAdapter
{
protected override ILog CreateLogger(string name)
{
return (ILog)typeof(NLogLogger).GetConstructor(
BindingFlags.NonPublic | BindingFlags.Instance, null, new Type[] { typeof(NLog.Logger) }, null)
.Invoke(new object[] { NLog.LogManager.GetLogger(name) });
}
}
public static void ConfigureLogging()
{
Common.Logging.LogManager.Adapter = new MyAdapter();
}
关于NLog 和 Common.Logging 的噩梦,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23504018/
我想更改 nlog 布局,以便显示两个条目之间的时间。这样的布局可能吗? 这是我现在的输出,如果在时间旁边有自之前进入以来经过的秒数,那就太好了。 2012-05-20 19:18:41.09
使用 NLog v4.4.12,我的 App.config 中有这个 这是我的 Variables.xml 文件内容 但是我在启动我的应
我有一个名为 的自定义布局渲染器工作 .它提供了几个项目,它们在我们的 app.config 中是这样使用的: 当
NLog 是否可以发出多行消息,以便每行都根据当前布局进行格式化?例如。 2015-12-17 11:37:38.0845 | 64 | INFO | ------------------------
我刚开始玩 nlog,注意到 nlog.xml 文件与 nlog.dll 一起被带到了应用程序的输出文件夹中。我不太清楚该文件的用途以及我是否应该将它作为我的应用程序安装的一部分或可以安全地删除它。有
是否可以/容易使用 Rhino Mocks 或类似方法模拟 NLog 日志方法? 最佳答案 使用 Nuget:install-package NLog.Interface 然后:ILogger log
目标: 当我打电话时Logger.Error("some message", e) ,其中 e是一些异常对象,它只记录消息,不记录异常信息。我需要它来输出异常消息和堆栈跟踪。任何想法我做
在生产环境中更改 nLog 日志记录级别的最佳做法是什么。我可以更改它的唯一方法是修改 NLog.config 文件,然后回收应用程序池。应该这样吗? 谢谢, 克里斯 最佳答案 如果你想改变日志配置而
我已经创建了一个通用实现 ILogger 并在这个包装器中实现了 NLog 实现方法。我的问题是我在我的解决方案中为整个 namspace 启用了错误严重性,但我还希望对“Employee”命名空间下
我在 NLog.config 中配置了两条规则: 我正在尝试使用以下代码写入第一个: LogEventInfo eventInfo = new LogEventInfo(); eventInfo.
我正在尝试将一堆应用程序使用的现有日志记录库转换为使用 NLog。现有的日志记录代码没有间接性,日志记录调用直接从调用者到 Web 服务调用。现有的日志记录代码是作为静态单例实现的。我需要以这样一种方
我有一个泛型类: public class GenericClass { private static readonly Logger Logger = LogManager.GetCurre
在我看来,NLog 中的内置日期格式没有正确包含时区。我们需要用尾随 Z 记录 UTC 时间,以便 Splunk 知道本地时间是什么,例如: {日期:universalTime=true:format
我们提供了一个用于日志记录的框架程序集,它在内部使用 nlog。我们还提供了一个嵌入式 nlog 配置作为我们程序集中的资源,并在启动时读取它(包装器中的静态构造函数,它使用 XmlLoggingCo
我这样编码: private static readonly ILogger Logger = LogManager.GetCurrentClassLogger(); public MyClass()
现在我这样做 LogManager.DisableLogging(); 但这需要再次部署我的代码,如何从 nlog 配置文件中禁用登录。 最佳答案 关于nlog - 从 Nlog.config 发
我想弄清楚如何阻止 NLog 替换我正在记录的字符串中的换行符。我希望输出包含所有换行符,而不是将整个输出放在一行中。 有人可以帮忙吗? 配置: 代码
作为从 NLog 切换到 Serilog 的一个步骤,我想重定向 NLog 的 LogManager.GetLogger(name) 的标准调用的标准接线,以桥接任何记录到 NLog 的代码,以便立即
为此,我需要一份详细/分步指南。我已经阅读了简要指南 ( example here ) 并下载了示例代码,但我仍然无法弄清楚如何使用 Nlog 登录到 CloudWatch。 当我在 NLog.con
我将 NLog 错误电子邮件文本的内容放入一个文件中,并使用 FileContents 渲染器进行渲染。如果布局渲染器产生空字符串,我想做的是隐藏 html 输出的某些部分 Request ticke
我是一名优秀的程序员,十分优秀!