1
module internal Logger.Utils
4 open System.Diagnostics
6 open System.IO.Compression
11 let extractNumberFromLogfilepath (path
: string) : int option =
15 let filename = path.Substring (path.LastIndexOf Path.DirectorySeparatorChar + 1)
16 let filenameWithoutExtension = filename.Remove (filename.IndexOf '.')
17 match Int32.TryParse filenameWithoutExtension with
21 let compress (filename : string) =
22 use inputStream = new FileStream (filename, FileMode.Open, FileAccess.Read)
23 let filenameCompressed = filename + COMPRESSED_FILE_POSTFIX
24 use compressedStream = new GZipStream (new FileStream (filenameCompressed, FileMode.Create, FileAccess.Write), CompressionLevel.Optimal)
25 inputStream.CopyTo compressedStream
27 let formatHeader (msg
: Message) =
29 "{0:yyyy-MM-dd HH:mm:ss.fff} [{1}] {{{2}}} ({3})",
33 (if String.IsNullOrEmpty msg
.ThreadName then sprintf
"%2i" msg
.ThreadId else sprintf "%s-%i" msg
.ThreadName msg.ThreadId)
36 let formatMessage (formatedHeader
: string) (msg : string) =
37 String.Format ("{0} : {1}", formatedHeader
, msg)
39 let moduleName = (System.Diagnostics.StackFrame 1).GetMethod().Module.Name
41 let callerModuleName () =
44 StackTrace().GetFrames ()
47 let name = frame
.GetMethod().Module.Name
48 if name <> moduleName then Some name else None