3

log4net ログを書き込む C# exe を取得しました。このexeを直接実行すると、ログは正常に機能します。ただし、F# スクリプト (拡張子 fsx) から exe を呼び出すと、エラーが発生します。

log4net:ERROR Failed to find configuration section 'log4net' in the application'
s .config file. Check your .config file for the <log4net> and <configSections> e
lements. The configuration section should look like: <section name="log4net" typ
e="log4net.Config.Log4NetConfigurationSectionHandler,log4net" />

誰でも助けることができますか?どうもありがとう

4

2 に答える 2

2

この exe ファイルの構成を f# アプリケーションの構成ファイルに挿入するか、コードでロガーを初期化する必要があります。f# スクリプトを実行するときに構成ファイルがあるかどうかはわかりません。

次のコードを使用して、config を c# exe の configfile に設定することができます。

AppDomain.CurrentDomain.SetData("APP_CONFIG_FILE", "c:/test.config);
于 2012-12-06T18:27:35.843 に答える
1

F# Interactive から C# .exe を呼び出す場合、現在の作業ディレクトリ (.NET が .config ファイルの読み込みを試みる場所) は、F# Interactive がインストールされているディレクトリです。

F# インタラクティブ スクリプトで、次のようにします。

// Change the current directory to the directory where the
// C# assembly was loaded from.
System.Environment.CurrentDirectory <-
    // TODO : Change 'MyType' to any public type from your C# assembly
    typeof<FSharpx.Text.Lexing.Position>.Assembly.Location

編集:よく考えてみると、上記のコードが機能するかどうかはわかりません。.config ファイルが遅延ロードされる (つまり、オンデマンドで) ことを前提としています。CLR が .exe のロードと同時に .config ファイルをロードする場合は、代わりに次のようにする必要があります。

// Change the current directory *before* referencing the C# assembly.
System.Environment.CurrentDirectory <- @"C:\blah";;

// Reference the C# assembly
#r @"C:\blah\foobar.exe";;
于 2012-12-06T18:34:04.090 に答える