f#的printf样式日志记录 [英] printf style logging for f#
问题描述
如何使用类似于log4net的日志记录库为f#设置printf样式的记录器. 我有Log.Debug,Info,Warn等功能,它们与log4net中的DebugFormat或InfoFormat相似.我尝试为我的Log类设置类型扩展名,可以使用printf样式(如Log.Debugf%s""foo")来调用它.我的通用日志函数如下所示:
How do i setup a printf-style logger for f# using logging library similar to log4net. i have Log.Debug, Info, Warn, etc. functions that are similar to DebugFormat or InfoFormat in log4net. i tried to setup type extensions for my Log class that i could call in printf style like Log.Debugf "%s" "foo". my generic log function looks like this:
let log format = Printf.kprintf (sprintf "%s") format
我无法使用扩展功能签名来登录到我的Debug函数... 我尝试使用Debugf格式和Debug
i am having trouble with the extension function signature to log to my Debug function... i tried using Debugf format and Debug
推荐答案
我对log4net并不熟悉,但是假设您正在登录到MessageBox(就像专家一样),则可以执行以下操作:
I'm not familiar with log4net, but assuming you're logging to a MessageBox (like the pros do), you can do the following:
let log format = Printf.kprintf (fun msg -> System.Windows.Forms.MessageBox.Show(msg)) format
在这种情况下,由于Show
需要一个字符串,因此可以将其缩短为:
In this case, since Show
takes a string, it can be shortened to:
let log format = Printf.kprintf System.Windows.Forms.MessageBox.Show format
这篇关于f#的printf样式日志记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!