2011-08-04 18 views
1

これは私がlog4netを使用しようとした2回目です。これは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ファイルを追加します:私は

私が示された例外やメッセージから何をすべきかを決定することはできません...それはOKであるべきだと思いますが、 :私のため

<?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

[assembly: log4net.Config.XmlConfigurator(Watch = true)]を挿入した同じダイレクトにコピーされlog4netのDLLですあなたのウィンドウがexe形式のようにory? –

+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

修正がassemblyinfo.cs

関連する問題