1

이것은 log4net을 사용하려고 시도한 두 번째 시간입니다. 이것은 Windows 양식 앱이며 모든 것이 정상적으로 설정되었다고 생각했지만 로그 파일이 생성되지 않았습니다. log4net.Config.XmlConfigurator.Configure() 제공 - "FileNotFoundException 네이티브/관리 된 경계를 넘었습니다"

public partial class GridForm : Form 
{ 
    public static readonly ILog log = LogManager.GetLogger(typeof(GridForm)); 

    public GridForm() 
    { 
     InitializeComponent(); 
              // Initialize log4net (make him read the app.config file) 
     log4net.Config.XmlConfigurator.Configure();  // this gives the exception 
    } 

내가 어떻게 참조하고 있습니다에 대한 약간의 불확실성이 : 그래서 내가 여기 log4net.Config.XmlConfigurator.Configure()를 추가 명시 적으로는 app.config 파일을 읽을 수 있도록 할 필요에 대해 몇 가지 조언을 발견 log4net.dll.

  • 솔루션에 2 개의 프로젝트가 있습니다. CBMI.Common은 클래스 라이브러리 프로젝트이고 CBMI.WinFormsUI는 내 양식 프로젝트 (시작 양식)입니다.
  • 나는 그 위치를 가리키는 내 양식 프로젝트에 참조 추가
  • CBMI.Common의 bin 디렉토리 (NOT의 bin \ debug 폴더)에 log4net.dll 복사 : CBMI.Common \ 함을

오류없이 컴파일됩니다.

System.IO.FileNotFoundException crossed a native/managed boundary 
    Message=Could not load file or assembly 'Log4net' or one of its dependencies. The system cannot find the file specified. 
    Source=mscorlib 
    FileName=Log4net 
    FusionLog==== Pre-bind state information === 
LOG: User = HPpavilion\john 
LOG: DisplayName = Log4net 
(Partial) 
WRN: Partial binding information was supplied for an assembly: 
WRN: Assembly Name: Log4net | 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/john/documents/visual studio 2010/Projects/CBMI.LatitudePostConverter/CBMI.WinFormsUI/bin/Debug/ 
LOG: Initial PrivatePath = NULL 
Calling assembly : System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a. 
=== 
LOG: This bind starts in default load context. 
LOG: Using application configuration file: C:\Users\john\documents\visual studio 2010\Projects\CBMI.LatitudePostConverter\CBMI.WinFormsUI\bin\Debug\CBMI.WinFormsUI.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/john/documents/visual studio 2010/Projects/CBMI.LatitudePostConverter/CBMI.WinFormsUI/bin/Debug/Log4net.DLL. 
LOG: Attempting download of new URL file:///C:/Users/john/documents/visual studio 2010/Projects/CBMI.LatitudePostConverter/CBMI.WinFormsUI/bin/Debug/Log4net/Log4net.DLL. 
LOG: Attempting download of new URL file:///C:/Users/john/documents/visual studio 2010/Projects/CBMI.LatitudePostConverter/CBMI.WinFormsUI/bin/Debug/Log4net.EXE. 
LOG: Attempting download of new URL file:///C:/Users/john/documents/visual studio 2010/Projects/CBMI.LatitudePostConverter/CBMI.WinFormsUI/bin/Debug/Log4net/Log4net.EXE. 

    StackTrace: 
     at System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMarkHandle stackMark, Boolean loadTypeFromPartialName, ObjectHandleOnStack type) 
     at System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark, Boolean loadTypeFromPartialName) 
     at System.RuntimeType.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark) 
     at System.Type.GetType(String typeName, Boolean throwOnError) 
     at System.Configuration.Internal.InternalConfigHost.System.Configuration.Internal.IInternalConfigHost.GetConfigType(String typeName, Boolean throwOnError) 
     at System.Configuration.Internal.DelegatingConfigHost.GetConfigType(String typeName, Boolean throwOnError) 
     at System.Configuration.TypeUtil.GetTypeWithReflectionPermission(IInternalConfigHost host, String typeString, Boolean throwOnError) 
    InnerException: 

완성도를 들어, 나는 의 app.config 파일을 추가합니다 : 나는

내가 표시된 발생한 예외 메시지에서 무엇을 확인할 수 없습니다 ... 그것은 확인을해야한다고 생각하지만, :

<?xml version="1.0" encoding="utf-8" ?> 
<configuration> 
<configSections> 
    <sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" > 
     <section name="CBMI.WinFormsUI.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" /> 
    </sectionGroup> 

    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,Log4net"/> 

</configSections> 

<userSettings> 
    <CBMI.WinFormsUI.Properties.Settings> 
     <setting name="DefaultRootFolder" serializeAs="String"> 
      <value /> 
     </setting> 
    </CBMI.WinFormsUI.Properties.Settings> 
</userSettings> 

<log4net> 
    <appender name="LogFileAppender" type="log4net.Appender.RollingFileAppender"> 
     <param name="File" value="log-file.txt"/> 
     <param name="AppendToFile" value="true"/> 
     <rollingStyle value="Size"/> 
     <maxSizeRollBackups value="10"/> 
     <maximumFileSize value="10MB"/> 
     <staticLogFileName value="true"/> 
     <layout type="log4net.Layout.PatternLayout"> 
      <param name="ConversionPattern" value="%-5p%d{yyyy-MM-dd hh:mm:ss} – %m%n"/> 
     </layout> 
    </appender> 
    <root> 
     <level value="DEBUG"/> 
     <appender-ref ref="LogFileAppender"/> 
    </root> 
</log4net> 

<startup> 
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/> 
</startup> 

</configuration> 
+0

가 log4net의 DLL이 같은 직접 복사되고있는 AssemblyInfo.cs에 [assembly: log4net.Config.XmlConfigurator(Watch = true)]를 삽입했다 오라는 귀하의 windows 양식을 exe로? –

+0

내 질문에 대한 감사드립니다. 아니요, log4net.dll이 내 bin \ debug 디렉토리에 복사되지 않습니다. 그게 일어날 일인가요? log4net.dll을 수동으로 bin \ debug에 복사했지만 아무런 차이가 없습니다. 언제든지 : log4net.Config.XmlConfigurator.Configure(); 내 생성자 (위와 같이)에서 실패합니다. 나는 GAC의 log4net을 가리 키기 위해 REFERENCE를 변경했다. 나를위한 해결책은 assemblyinfo.cs에 [assembly : log4net.Config.XmlConfigurator (Watch = true)]를 삽입하는 것이 었습니다. –

답변

4

나에 대한 수정은

관련 문제