【问题标题】:How to set up NLog in F# script (fsx)如何在 F# 脚本 (fsx) 中设置 NLog
【发布时间】:2014-01-30 08:35:23
【问题描述】:
我有一些使用 NLog 进行日志记录的 f# 项目。
当我使用项目生成的 .exe 时,日志记录工作正常,我在文件或控制台中看到输出。
但是现在我需要使用我在 fsx-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
一切正常,但我在控制台和文件中都没有看到 NLog 的输出。我错过了什么?
【问题讨论】:
标签:
logging
f#
console-application
nlog
【解决方案1】:
我目前无法访问计算机进行检查,但在 fsi 脚本中被触发时,您的 NLog 可能无法获取其配置。
您可能希望在已编译的 F# 项目中找到 nlog.config 文件并将其复制到目录中,您的 fsi.exe(FsiAnyCPU.exe 对于 64 位 fsi)与 Fsi.exe.config( FsiAnyCPU.exe.config)。
对于 Windows 上的 F# 3.x,位置通常是 C:\Program Files (x86)\Microsoft SDKs\F#\3.0\Framework\v4.0。
或者,您可以切换到configuring NLog from your code 并从您的脚本运行配置片段。
【解决方案2】:
我不知道 NLog,但可能你需要重定向输出。
Console.SetOut(someClassDerivingFromStringWriter)
Console.SetError(someClassDerivingFromStringWriter)