2012-12-06 3 views
3

log4net 로그를 작성하는 C# exe가 있습니다. 이 exe를 직접 실행하면 로깅이 제대로 작동합니다. 나는 (확장 FSX)와 함께 F 번호 스크립트에서 EXE를 호출하는 경우 그러나, 나는F # 스크립트 호출시 log4net 문제 C# 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" /> 

사람이 도울 수있는 오류가? 고마워요

+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")를 사용하여 C# app의 config 파일을 config로 설정할 수 있습니다. –

+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";;