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 InfoFo
You can use standard logging subsystem that defined in System.Diagnostic namespace. You shall be sure that your logging enviromnet correctly initialized. For example something like this (part of example in C#) but it easy is linked with f# code.
Trace.Listeners.Clear();
try {
TextWriterTraceListener infoTextLogger = new AlignedTextWriterTraceListener(@"c:\temp\log.log");
infoTextLogger.Filter = new EventTypeFilter(SourceLevels.All);
infoTextLogger.TraceOutputOptions = TraceOptions.DateTime | TraceOptions.ProcessId | TraceOptions.ThreadId;
Trace.Listeners.Add(infoTextLogger);
TextWriterTraceListener consoleWriter = new AlignedTextWriterTraceListener(System.Console.Out);
consoleWriter.Filter = new EventTypeFilter(SourceLevels.Information);
Trace.Listeners.Add(consoleWriter);
} catch (Exception exp) {
throw exp;
}
AlignedTextWriterTraceListener.TraceSourceNameLength = SOURCE_NAME_FIELD_LENGTH;
Trace.AutoFlush = true;
Trace.TraceInformation("Logging subsystem has been initiated");
so in f#
open System
open System.Diagnostics
module ClientConsole =
let Run _ =
Trace.TraceInformation("Client started");
For more convenient you can use another trace listener that definded by third party programmer. For example lool at : AlignedTextWriterTraceListener