我公司的标准日志工具是NLog.我正在尝试介绍Quartz.net,并询问它是否可以使用NLog而不是Log4Net.
我知道我可以重新编译使用NLog,但是如果可能的话,我想从配置文件中做到这一点.
我目前正致力于将一个大型项目移动到使用Common.Logging,我希望能够将记录事件输出到多个第三方日志记录实现.
我们目前有一个内部开发的跟踪库,我们希望继续使用它来跟踪和调试消息.我还想开始使用log4net将一些消息发送到数据库,以便在某些级别进行报告或发送电子邮件通知.
我正在寻找的是这样的:
<common>
<logging>
<factoryAdapter type="CustomTraceFactoryAdapter, MyAssembly">
<arg key="configType" value="INLINE"/>
</factoryAdapter>
<factoryAdapter type="Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter, Common.Logging.Log4Net">
<arg key="configType" value="INLINE"/>
</factoryAdapter>
</logging>
</common>
Run Code Online (Sandbox Code Playgroud)
使用开箱即用的配置选项有没有办法做到这一点?
我的问题源自这个问题,其中一条评论表明DEBUG日志级别比TRACE更精细.看看TRACE和DEBUG在.NET中意味着什么,这似乎是有道理的,因为根据定义,DEBUG(作为一个概念)在生产中从未见过.这可能是他们未被用作企业库中的事件类型的原因.另一方面,我所知道的所有其他实现(log4net,nlog,common.logging)都将TRACE作为比DEBUG更精细的级别.也就是说,在DEBUG日志级别运行的应用程序不会写入TRACE日志.
我们需要实现自己的日志框架,我想知道是否有更多的人认为DEBUG真的应该是最"垃圾"的日志级别?或者,如果我们的新框架应该为新开发人员提供一些易于使用的熟悉程序等,您会认为这是一个错误吗?
谢谢.
我通过 nuget 添加了 common.logging.log4net 到我的 Visual Studio 2012 解决方案。
common.logging.log4net 版本。- 2.0.1 common.logging 版本。- 2.0.0 log4net - 版本。1.2.10
当我在本地构建/运行它时,我通过浏览器看到以下异常:
无法加载文件或程序集“Common.Logging”或其依赖项之一。定位的程序集的清单定义与程序集引用不匹配。(来自 HRESULT 的异常:0x80131040) 描述:在执行当前 Web 请求期间发生未处理的异常。请查看堆栈跟踪以获取有关错误及其在代码中的来源的更多信息。
异常详细信息:System.IO.FileLoadException:无法加载文件或程序集“Common.Logging”或其依赖项之一。定位的程序集的清单定义与程序集引用不匹配。(来自 HRESULT 的异常:0x80131040)
堆栈跟踪:
[FileLoadException: 无法加载文件或程序集“Common.Logging”或其依赖项之一。定位的程序集的清单定义与程序集引用不匹配。(来自 HRESULT 的异常:0x80131040)]
[FileLoadException: 无法加载文件或程序集“Common.Logging, Version=2.1.1.0, Culture=neutral, PublicKeyToken=af08829b84f0328e”或其依赖项之一。定位的程序集的清单定义与程序集引用不匹配。(HRESULT 异常:0x80131040)] System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean for BooleanIntrospection)
System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(的AssemblyName assemblyRef,证据assemblySecurity,RuntimeAssembly reqAssembly,StackCrawlMark&stackMark,IntPtr的pPrivHostBinder,布尔throwOnFileNotFound,布尔forIntrospection,布尔suppressSecurityChecks)210
System.Reflection.RuntimeAssembly.InternalLoad(字符串assemblyString,证据assemblySecurity,StackCrawlMark&stackMark , IntPtr pPrivHostBinder, Boolean for Introspection) +242
System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean for Introspection) +17 System.Reflection.Assembly.Load(String assemblyString) +35 …
我想在项目包装器上使用Common.logging和log4net,我在我的日志项目中创建了一个log4net.config文件并配置了我的web.config文件,但是当我尝试记录任何内容时我得到了一个异常(错误,信息等) ).我认为问题出在web.config文件中,但我检查了,我没有看到任何错误.
异常错误是
为common/logging创建配置节处理程序时出错:无法创建类型'Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter,Common.Logging.Log4Net
DLL的
Common.Logging.2.0.0
Common.Logging.Log4Net.2.0.1
log4net.1.2.10
Run Code Online (Sandbox Code Playgroud)
包装类
using System;
using System.Diagnostics;
using Common.Logging;
using System.Reflection;
namespace LoggerL
{
public class Logger
{
private static readonly ILog log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
//static Logger()
//{
// XmlConfigurator.Configure();
//}
public static void Info(string msg = "")
{
var method = new StackFrame(1).GetMethod();
var name = method.DeclaringType.FullName + "." + method.Name + "(";
foreach (var item in method.GetParameters())
{
name += item.ParameterType.Name + " " + item.Name + ", ";
}
name = …Run Code Online (Sandbox Code Playgroud) 所以我尝试了所有我能找到的东西来让这两个一起玩.
我已经安装了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>
Run Code Online (Sandbox Code Playgroud)
我正在使用nuget NLog.Configuration包,所以我的nlog配置在一个名为NLog.config的单独文件中:
<?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. …Run Code Online (Sandbox Code Playgroud) 如何使用C#中的变量动态更改FileName?我的想法是创建一个像日志文件Log_<UserId_From_DB>_${date:format=yyyy-MM-dd}.log.有任何想法吗?
我编写了类库来支持使用 NLog 和 log4net 以及 Common.Logging 编写日志。当我测试项目时出现错误
无法加载文件或程序集“Common.Logging,Version=3.3.1.0,Culture=neutral,PublicKeyToken=af08829b84f0328e”或其依赖项之一。找到的程序集的清单定义与程序集引用不匹配。(HRESULT 异常:0x80131040)
刷新日志:
=== Pre-bind state information ===
LOG: DisplayName = Common.Logging, Version=3.3.1.0, Culture=neutral, PublicKeyToken=af08829b84f0328e
(Fully-specified)
LOG: Appbase = file:///C:/Source/Hits2000/Web-Applications/WinhitsWebApi/WinhitsWebApi.ApiService/
LOG: Initial PrivatePath = C:\Source\Hits2000\Web-Applications\WinhitsWebApi\WinhitsWebApi.ApiService\bin
Calling assembly : Common.Logging.Log4Net1211, Version=3.3.1.0, Culture=neutral, PublicKeyToken=af08829b84f0328e.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Source\Hits2000\Web-Applications\WinhitsWebApi\WinhitsWebApi.ApiService\web.config
LOG: Using host configuration file: C:\Users\Administrator\Documents\IISExpress\config\aspnet.config
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Post-policy reference: Common.Logging, Version=3.3.1.0, Culture=neutral, PublicKeyToken=af08829b84f0328e
LOG: Attempting download of new URL …Run Code Online (Sandbox Code Playgroud) 我正在尝试启用 Common.Logging.Log4Net 将所有类型的日志写入日志文件。教程使它看起来如此简单,但我不知道我做错了什么。这些是我正在采取的步骤:
将以下行添加到默认的 web.config:
<common>
<logging>
<factoryAdapter type="Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter, Common.Logging.Log4Net">
<arg key="configType" value="INLINE" />
</factoryAdapter>
</logging>
</common>
<log4net>
<root>
<level value="ALL" />
<appender-ref ref="FileAppender" />
</root>
<appender name="FileAppender" type="log4net.Appender.FileAppender" >
<param name="File" value="C:\Users\MyName\Downloads\log.txt" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %level %logger - %message%newline" />
</layout>
</appender>
</log4net>
Run Code Online (Sandbox Code Playgroud)确保应用程序。池身份帐户对我尝试保存日志文件的路径具有 RW 访问权限。
出于测试目的,从代码中抛出一个随机异常。
我错过了什么吗?有没有办法调试log4net?请帮助这个可怜的灵魂。谢谢你。
我正在尝试使用common.logging将记录添加到使用Quartz.net构建的Windows Web服务,以使用log4net写入日志文件.
我的App.config看起来像这样:
<?xml version="1.0"?>
<configuration>
<configSections>
<sectionGroup name="common">
<section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging"/>
</sectionGroup>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
<section name="quartz" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0,Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</configSections>
<quartz>
<add key="quartz.scheduler.instanceName" value="CommerceScheduler" />
<add key="quartz.threadPool.type" value="Quartz.Simpl.SimpleThreadPool, Quartz" />
<add key="quartz.threadPool.threadCount" value="10" />
<add key="quartz.threadPool.threadPriority" value="Normal" />
</quartz>
<appSettings>
<add key="configpath" value="C:\Projects\SiteScheduler\SiteScheduler\Schedule.xml"/>
</appSettings>
<common>
<logging>
<factoryAdapter type="Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter, Common.Logging.Log4net">
<arg key="configType" value="INLINE" />
</factoryAdapter>
</logging>
</common>
<log4net>
<root>
<level value="DEBUG" />
<appender-ref ref="LogFileAppender" />
</root>
<appender name="LogFileAppender" type="log4net.Appender.RollingFileAppender" >
<param name="File" value="log.txt" />
<param …Run Code Online (Sandbox Code Playgroud) common.logging ×10
log4net ×6
c# ×4
nlog ×4
logging ×2
quartz.net ×2
.net ×1
asp.net-mvc ×1
nuget ×1