简体   繁体   中英

How to set up NLog in F# script (fsx)

i have some f# projects which use NLog for logging. And logging works fine when i use .exe produced by projects, i see output in files or console.

But now i need to use my types (which uses logging) defined in my project in fsx-script, and i got in trouble.

Part of my script

#r "NLog.dll"
#r "Emulators.dll" // contains some types which uses NLog
#r "DeviceEmulator.exe" // also contains types which uses NLog

// instantiating and run objects

All works fine but i does not see output from NLog neither in console nor in file. What have i missed?

I'm currently have no access to computer to check, but likely your NLog cannot pick up its configuration, when being fired within a fsi script.

You may want finding nlog.config file within your compiled F# projects and copying it to the directory, where your fsi.exe ( FsiAnyCPU.exe for 64-bit fsi ) is located side by side with Fsi.exe.config ( FsiAnyCPU.exe.config ).

For F# 3.x on Windows the location is usually C:\\Program Files (x86)\\Microsoft SDKs\\F#\\3.0\\Framework\\v4.0 .

Alternatively, you may switch to configuring NLog from your code and run the configuration piece from your script.

I dont know NLog, but may be you need to redirect the output.

Console.SetOut(someClassDerivingFromStringWriter)
Console.SetError(someClassDerivingFromStringWriter)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM