我正在尝试使用以下日志记录程序集配置控制台应用程序:
如果以编程方式配置记录器,那么一切正常:
NameValueCollection properties = new NameValueCollection(); properties["showDateTime"] = "true";
Common.Logging.LogManager.Adapter = new Common.Logging.Simple.ConsoleOutLoggerFactoryAdapter(properties);
Run Code Online (Sandbox Code Playgroud)
但是,如果我尝试使用以下配置文件启动它,它会爆炸:
<?xml version="1.0"?>
<configuration>
<configSections>
<sectionGroup name="common">
<section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging" />
</sectionGroup>
</configSections>
<common>
<logging>
<factoryAdapter type="Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter, Common.Logging.Log4Net">
<arg key="configType" value="FILE-WATCH"/>
<arg key="configFile" value="~/Log4NET.xml"/>
</factoryAdapter>
</logging>
</common>
</configuration>
Run Code Online (Sandbox Code Playgroud)
这些是相关的错误消息:
{"Unable to cast object of type 'System.Configuration.DefaultSection' to type 'System.Configuration.AppSettingsSection'."}
{"Failed obtaining configuration for Common.Logging from configuration section 'common/logging'."}
Run Code Online (Sandbox Code Playgroud)
它似乎无法解析我的配置文件,是否有人知道正确的格式应该是什么,或者是其他错误的东西?我使用官方文档创建了配置文件.
编辑:Common.Logging 2.1.1于2012年6月9日发布,Github页面相当活跃,作者专门评论了项目的健康状况.
我们正在考虑在新的.NET项目中使用Common.Logging,但我有点担心项目似乎变得不活跃.该主页最后一次更新于2009年,SourceForge上的最新版本于2010年创建.我已经发现与NLog 2不兼容,我担心随着时间的推移,这可能会成为一个更大的问题.我注意到Enterprise Library 5.0没有列为兼容,但我没有尝试过.
是否有其他替代方案可提供类似的通用接口?
我正在尝试安装一个nuget包,它错误地指定了它的一个依赖项.Common.Logging.Log4Net需要log4net = 1.2.10,但是nuget包指定log4net> = 1.2.10.即使我手动安装旧版本的log4net,当我安装Common.Logging.Log4Net时,nuget也会将log4net升级到1.2.11.我怎样才能让nuget绕过依赖解析或者至少更喜欢安装了足够版本的软件包?
我正在尝试使用NuGet包来配置Common.Logging以在ASP.Net MVC项目中使用NLog2.根据以下URL提供的信息,我相信我的记录器配置正确,但我仍然遇到配置错误.
我按照说明将以下内容添加到web.config中:
<configuration>
<configSections>
<section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog"/>
<sectionGroup name="common">
<section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging" />
</sectionGroup>
</configSections>
<common>
<logging>
<factoryAdapter type="Common.Logging.NLog.NLogLoggerFactoryAdapter, Common.Logging.NLog20">
<arg key="configType" value="INLINE" />
</factoryAdapter>
</logging>
</common>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<targets>
<target name="logfile" xsi:type="file" filename="e:\logfile.txt" layout="${date:format=yyyy/MM/dd HH:mm:ss} ${message}" />
</targets>
<rules>
<logger name="*" minlevel="Trace" writeTo="logfile" />
</rules>
</nlog>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<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>
</configuration>
Run Code Online (Sandbox Code Playgroud)
据我所知,这是我应该做的一切,但是当我尝试运行Web项目时,我遇到了配置错误......
分析器错误消息:为common/logging创建配置节处理程序时出错:无法创建类型'Common.Logging.NLog.NLogLoggerFactoryAdapter,Common.Logging.NLog20'
任何人都可以提供有关缺失或错误的建议吗?
我今天尝试使用这些,并且正在寻找版本不匹配,因为它正在寻找NLog v1.
Common.Logging是否支持NLog v2?
如果没有,是否有人知道是否可以安全地使用程序集版本重定向?
我尝试打电话时遇到以下异常
var log = LogManager.GetLogger(this.GetType());
Run Code Online (Sandbox Code Playgroud)
Common.Logging.dll中发生了'Common.Logging.ConfigurationException'类型的第一次机会异常
Common.Logging.dll中发生了'Common.Logging.ConfigurationException'类型的无法处理的异常
附加信息:无法从配置部分'common/logging'获取Common.Logging的配置.
这是一个引用的.NET 4应用程序
我的app.config有以下内容:
<?xml version="1.0"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
<configSections>
<sectionGroup name="common">
<section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging" />
</sectionGroup>
</configSections>
<common>
<logging>
<factoryAdapter type="Common.Logging.Simple.ConsoleOutLoggerFactoryAdapter, Common.Logging">
<arg key="level" value="ALL" />
<arg key="showLogName" value="true" />
<arg key="showDataTime" value="true" />
<arg key="dateTimeFormat" value="yyyy/MM/dd HH:mm:ss:fff" />
</factoryAdapter>
</logging>
</common>
</configuration>
Run Code Online (Sandbox Code Playgroud)
我试着像这样打电话:
var log = LogManager.GetLogger(this.GetType());
log.Debug(m => m("testing"));
Run Code Online (Sandbox Code Playgroud)
我错过了什么?
我正在尝试使用Common.Logging程序集来替换默认的nHibernate Log4net日志记录.
我在我的项目中添加了一个引用:
Common.Logging.dll v2.0
NHibernate.Logging.CommonLogging.dll v1.2.0.4000
,然后将以下内容添加到我的Web.config中:
<add key="nhibernate-logger" value="NHibernate.Logging.CommonLogging.CommonLoggingLoggerFactory, Hibernate.Logging.CommonLogging"/>
Run Code Online (Sandbox Code Playgroud)
我的目标是用Enterprise Library 5.0替换Log4net日志记录,但我现在只是一步一步.
当我现在运行我的应用程序时,我得到以下异常:
The type initializer for 'NHibernate.Cfg.Configuration' threw an exception. =>
The type initializer for 'NHibernate.LoggerProvider' threw an exception. =>
The type initializer for 'NHibernate.LoggerProvider' threw an exception. =>
Unable to instantiate: =>
Value cannot be null.\r\nParameter name: type
at NHibernate.LoggerProvider.LoggerFor(Type type)
at NHibernate.Cfg.Configuration..cctor()
Run Code Online (Sandbox Code Playgroud)
有没有什么我缺少使用Common.Logging与nHibernate?我已经尝试按照我在网上找到的说明但是它无法正常工作,我找不到解决方案:(
我正在使用NHibernate v3.2.0.4000.
PS.这是我在这个网站上的第一篇文章很抱歉如果格式不对,我会接受建设性的批评:o)
查看使用Common.Logging for .NET 的项目,我注意到有些类将logger实例声明为类静态成员.例如:
public class HelloJob : IJob
{
private static ILog _log = LogManager.GetLogger(typeof(HelloJob));
public HelloJob()
{
}
public virtual void Execute(IJobExecutionContext context)
{
_log.Info(string.Format("Hello World! - {0}", System.DateTime.Now.ToString("r")));
}
}
Run Code Online (Sandbox Code Playgroud)
在其他类中,记录器被声明为实例成员:
public class SimpleExample : IExample
{
public virtual void Run()
{
ILog log = LogManager.GetLogger(typeof (SimpleExample));
log.Info("------- Initializing ----------------------");
// etc
}
}
Run Code Online (Sandbox Code Playgroud)
是否有理由偏好一种方法或另一种方法?
在哪些情况下推荐每种方法?它与线程安全有关吗?
如果我刚刚宣布一个带有静态"记录器"成员的"Logger"类并且使用了整个项目(除了我在实践中会有一个全局变量的问题),这会是一个问题吗?
我有一个Wpf .net 4.0 C#项目,我试图从使用Log4Net迁移到使用NLog作为Common.LoggingFaçade后面的日志库.我原本以为这是一件容易的事,但你知道他们说的是什么,没有什么比这更容易了.
我用过NuGet来:
在app.config文件中我有:
<common>
<logging>
<factoryAdapter type="Common.Logging.NLog.NLogLoggerFactoryAdapter, Common.Logging.NLog">
<arg key="configType" value="FILE" />
<arg key="configFile" value="~/NLog.config" />
</factoryAdapter>
</logging>
</common>
Run Code Online (Sandbox Code Playgroud)
......而且......
<dependentAssembly>
<assemblyIdentity name="NLog" publicKeyToken="5120e14c03d0593c" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.0.1.0" newVersion="2.0.1.0" />
</dependentAssembly>
Run Code Online (Sandbox Code Playgroud)
当我运行应用程序时,我收到一个错误说明
'在类型'NameSpace.Shell.AppBootstrapper'上调用与指定绑定约束匹配的构造函数引发了异常.行号'8'和行位置'18'.
内在的例外是:
{"无法加载一个或多个请求的类型.请检索LoaderExceptions属性以获取更多信息."}
说Loader异常,只有一个,是:
{"无法从程序集'NLog加载类型'NLog.TargetWithLayout',Version = 2.0.1.0,Culture = neutral,PublicKeyToken = 5120e14c03d0593c'.":"NLog.TargetWithLayout"}
有没有人克服这个问题或有解决方法NLog working with Common.Logging?
为了不发布长期问题,我没有包含该NLog.config文件,但我可以,如果这将是有益的.
我正在尝试实现Quartz.Net.只要没有配置日志记录一切正常(调试输出显示"找不到配置部分 - 抑制日志输出").
启用日志记录后,我将收到以下错误:无法从配置部分"common/logging"获取Common.Logging的配置.
内部异常:为common/logging创建配置节处理程序时发生错误:无法创建类型'Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter,Common.Logging.Log4net'
我用了几个资源,这其中以varify我的配置,但据我看到它应该是正确的.
我的app.config:
<configSections>
<section name="quartz" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0,Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<sectionGroup name="common">
<section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging" />
</sectionGroup>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
</configSections>
<common>
<logging>
<factoryAdapter type="Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter, Common.Logging.Log4net">
<arg key="configType" value="INLINE" />
</factoryAdapter>
</logging>
</common>
<log4net>
<appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender">
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%-6p%d{yyyy-MM-dd hh:mm:ss} – %m%n" />
</layout>
</appender>
<root>
<level value="DEBUG" />
<appender-ref ref="ConsoleAppender" />
</root>
</log4net>
<quartz>
<add key="quartz.scheduler.instanceName" value="Driver.Service.Scheduler" />
<add …Run Code Online (Sandbox Code Playgroud) c# log4net log4net-configuration common.logging quartz.net-2.0
common.logging ×10
c# ×5
nlog ×4
logging ×3
.net ×2
log4net ×2
app-config ×1
asp.net-mvc ×1
nhibernate ×1
nuget ×1