实现自定义 log4net PatternLayout
Implementing a custom log4net PatternLayout
我需要 log4net 来生成 CSV 文件并发现了 this article that implements one。我的问题是如何将该代码集成到我的 Web 项目中。直接复制粘贴让 ReSharper 坚持将命名空间从“CsvLogging”更改为“MyApp.Web”,这在现在,Web 项目的程序集现在有一个名为“CsvLogging”的 class。
但是 log4net 不高兴并抛出了下面粘贴的错误。
我的 appender 配置如下:
<layout type=" MyApp.Web.CsvLogging.CsvPatternLayout, MyApp.Web.CsvLogging">
...根据我对 this article on how to reference a custom pattern 的阅读,应该是正确的。
log4net:ERROR Failed to find type [ MyApp.Web.CsvLogging.CsvPatternLayout, MyApp.Web.CsvLogging]
System.IO.FileNotFoundException: Could not load file or assembly 'MyApp.Web.CsvLogging' or one of its dependencies. The system cannot find the file specified.
File name: 'MyApp.Web.CsvLogging'
at System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMarkHandle stackMark, IntPtr pPrivHostBinder, Boolean loadTypeFromPartialName, ObjectHandleOnStack type)
at System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean loadTypeFromPartialName)
at System.RuntimeType.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark)
at System.Type.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase)
at log4net.Util.SystemInfo.GetTypeFromString(Assembly relativeAssembly, String typeName, Boolean throwOnError, Boolean ignoreCase)
at log4net.Util.SystemInfo.GetTypeFromString(String typeName, Boolean throwOnError, Boolean ignoreCase)
at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.CreateObjectFromXml(XmlElement element, Type defaultTargetType, Type typeConstraint)
您有一个名为 MyApp.Web.CsvLogging
的 class,但您的程序集仍命名为 MyApp.Web
尝试以下操作:
<layout type=" MyApp.Web.CsvLogging.CsvPatternLayout, MyApp.Web">
程序集的 .net 命名基本上是 "namespace.class, assembly"
我需要 log4net 来生成 CSV 文件并发现了 this article that implements one。我的问题是如何将该代码集成到我的 Web 项目中。直接复制粘贴让 ReSharper 坚持将命名空间从“CsvLogging”更改为“MyApp.Web”,这在现在,Web 项目的程序集现在有一个名为“CsvLogging”的 class。
但是 log4net 不高兴并抛出了下面粘贴的错误。
我的 appender 配置如下:
<layout type=" MyApp.Web.CsvLogging.CsvPatternLayout, MyApp.Web.CsvLogging">
...根据我对 this article on how to reference a custom pattern 的阅读,应该是正确的。
log4net:ERROR Failed to find type [ MyApp.Web.CsvLogging.CsvPatternLayout, MyApp.Web.CsvLogging]
System.IO.FileNotFoundException: Could not load file or assembly 'MyApp.Web.CsvLogging' or one of its dependencies. The system cannot find the file specified.
File name: 'MyApp.Web.CsvLogging'
at System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMarkHandle stackMark, IntPtr pPrivHostBinder, Boolean loadTypeFromPartialName, ObjectHandleOnStack type)
at System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean loadTypeFromPartialName)
at System.RuntimeType.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark)
at System.Type.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase)
at log4net.Util.SystemInfo.GetTypeFromString(Assembly relativeAssembly, String typeName, Boolean throwOnError, Boolean ignoreCase)
at log4net.Util.SystemInfo.GetTypeFromString(String typeName, Boolean throwOnError, Boolean ignoreCase)
at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.CreateObjectFromXml(XmlElement element, Type defaultTargetType, Type typeConstraint)
您有一个名为 MyApp.Web.CsvLogging
的 class,但您的程序集仍命名为 MyApp.Web
尝试以下操作:
<layout type=" MyApp.Web.CsvLogging.CsvPatternLayout, MyApp.Web">
程序集的 .net 命名基本上是 "namespace.class, assembly"