log4net异步中的FileNotFoundException异常

时间:2016-05-02 10:06:01

标签: c# asynchronous logging log4net

我正在尝试使用log4net创建一个用于日志记录的库我从as shown in image.安装了log4net.async,我从控制台应用程序调用它来登录数据库和文件。

它在log4net内部日志中给出了错误

log4net: Configuration update mode [Merge].
log4net: Loading Appender [asyncForwarder] type: [Log4Net.Async.AsyncForwardingAppender,Log4Net.Async]
log4net:ERROR Could not create Appender [asyncForwarder] of type [Log4Net.Async.AsyncForwardingAppender,Log4Net.Async]. Reported error follows.
System.IO.FileNotFoundException: Could not load file or assembly 'Log4Net.Async' or one of its dependencies. The system cannot find the file specified.
File name: 'Log4Net.Async'
   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.ParseAppender(XmlElement appenderElement)

=== Pre-bind state information ===
LOG: DisplayName = Log4Net.Async
(Partial)
WRN: Partial binding information was supplied for an assembly:
WRN: Assembly Name: Log4Net.Async | Domain ID: 1
WRN: A partial bind occurs when only part of the assembly display name is provided.
WRN: This might result in the binder loading an incorrect assembly.
WRN: It is recommended to provide a fully specified textual identity for the assembly,
WRN: that consists of the simple name, version, culture, and public key token.
WRN: See whitepaper http://go.microsoft.com/fwlink/?LinkId=109270 for more information and common solutions to this issue.
LOG: Appbase = file:///C:/Users/vmekaxp/Documents/Visual Studio 2013/Projects/LogForNetAsync/Test/bin/Debug/
LOG: Initial PrivatePath = NULL
Calling assembly : log4net, Version=1.2.13.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Users\vmekaxp\Documents\Visual Studio 2013\Projects\LogForNetAsync\Test\bin\Debug\Test.vshost.exe.Config
LOG: Using host configuration file:
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///C:/Users/vmekaxp/Documents/Visual Studio 2013/Projects/LogForNetAsync/Test/bin/Debug/Log4Net.Async.DLL.
LOG: Attempting download of new URL file:///C:/Users/vmekaxp/Documents/Visual Studio 2013/Projects/LogForNetAsync/Test/bin/Debug/Log4Net.Async/Log4Net.Async.DLL.
LOG: Attempting download of new URL file:///C:/Users/vmekaxp/Documents/Visual Studio 2013/Projects/LogForNetAsync/Test/bin/Debug/Log4Net.Async.EXE.
LOG: Attempting download of new URL file:///C:/Users/vmekaxp/Documents/Visual Studio 2013/Projects/LogForNetAsync/Test/bin/Debug/Log4Net.Async/Log4Net.Async.EXE.

log4net:ERROR Appender named [asyncForwarder] not found.
log4net: Hierarchy Threshold []
log4net: No appenders could be found for logger [name] repository [log4net-default-repository]
log4net: Please initialize the log4net system properly.
log4net:     Current AppDomain context information:
log4net:        BaseDirectory   : C:\Users\vmekaxp\Documents\Visual Studio 2013\Projects\LogForNetAsync\Test\bin\Debug\
log4net:        FriendlyName    : Test.vshost.exe
log4net:        DynamicDirectory:
log4net: Shutdown called on Hierarchy [log4net-default-repository]

我的配置

<appender name="asyncForwarder" type="Log4Net.Async.AsyncForwardingAppender,Log4Net.Async">
      <level value="INFO"></level>
      <appender-ref ref="GeneralRollingFileAppender" />
      <appender-ref ref="ErrorRollingFileAppender" />
      <appender-ref ref="AdoNetAppender" />

      <bufferSize value="200000" />
    </appender>
    <root>

      <appender-ref ref="asyncForwarder" />
    </root>

1 个答案:

答案 0 :(得分:0)

由于程序集未在代码中直接引用,因此可能未将其复制到bin文件夹中。

尝试将其包含在Visual Studio项目中,但将其属性设置为

  • 构建Acton =内容
  • 复制到输出目录=始终复制

另一个选择是尝试将对Log4Net.Async.DLL的引用直接添加到您的顶级项目(控制台应用程序)。