2012-12-06 30 views
3

我得到了一個寫入log4net日誌的C#exe文件。如果我直接運行這個exe文件,記錄工作正常。 然而,如果我所說的EXE從F#腳本(擴展名爲FSX),我有錯誤當F#腳本調用C#exe時出現log4net問題

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" /> 

任何人都可以幫忙嗎?非常感謝

+0

你可以包括在呼喚你的問題的C#exe文件的F#代碼? –

回答

2

您應該將此exe文件的配置插入到您的f#應用程序的配置文件中,或者在代碼中初始化記錄器。我不確定當你運行f#腳本時有配置文件。

您可以嘗試配置設置到C#的EXE CONFIGFILE與代碼:

AppDomain.CurrentDomain.SetData("APP_CONFIG_FILE", "c:/test.config); 
+0

F#腳本由F#Interactive(fsi.exe)運行。 – kvb

+0

謝謝,我知道。您可以嘗試使用AppDomain.CurrentDomain.SetData(「APP_CONFIG_FILE」,「c:/test.config」)將config配置爲您的c#應用程序的配置文件; –

+0

我只是說F#腳本的相關配置文件是fsi.exe.config。 – kvb

1

當您從F#互動,當前工作目錄打電話給你的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";; 
相關問題