Skip to content

Instantly share code, notes, and snippets.

@cboudereau
Created May 9, 2017 15:04
Show Gist options
  • Save cboudereau/20c5a5e2e73815b7eb49e448e7f66d61 to your computer and use it in GitHub Desktop.
Save cboudereau/20c5a5e2e73815b7eb49e448e7f66d61 to your computer and use it in GitHub Desktop.
let log = Log.logger "WebService"
let logger =
let convertLevel = function
| Logging.LogLevel.Debug -> LogLevel.Debug
| Logging.LogLevel.Verbose -> LogLevel.Trace
| Logging.LogLevel.Info -> LogLevel.Info
| Logging.LogLevel.Warn -> LogLevel.Warn
| Logging.LogLevel.Error -> LogLevel.Error
| Logging.LogLevel.Fatal -> LogLevel.Fatal
let log = LogManager.GetLogger("WebService")
let culture = Globalization.CultureInfo.InvariantCulture
{ new Logging.Logger with
member __.Log(level: Logging.LogLevel) (msg: unit -> Logging.LogLine): unit =
let lvl = convertLevel level
if log.IsEnabled lvl then
let line = msg()
match line.``exception`` with
| None -> log.Log(LogEventInfo(lvl, line.path, culture, line.message, null))
| Some ex-> log.Log(LogEventInfo(lvl, line.path, culture, line.message, null, ex)) }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment