public T CreateLogFactory <T>(INewLineStrategy newLineStrategy, ITraceFormatStrategy traceFormatStrategy, IMessageFormatStrategy messageFormatStrategy) where T : class, ILogFactory, new() { return(new T { NewLineStrategy = newLineStrategy, TraceFormatStrategy = traceFormatStrategy, MessageFormatStrategy = messageFormatStrategy }); }
public StreamLogWriter(System.IO.Stream stream, INewLineStrategy newLineStrategy, IMessageFormatStrategy messageFormatStrategy) { if (stream == null || stream.Equals(System.IO.Stream.Null)) { throw new ArgumentNullException(nameof(stream), "not available to operate with a null stream"); } this.NewLineStrategy = newLineStrategy; this.MessageFormatStrategy = messageFormatStrategy; this._writer = new StreamWriter(stream); this._writer.AutoFlush = true; this.Items = new LogCollection(); }
public string FormatMessage(ILog log, INewLineStrategy newLineStrategy) { var param = new List <string>(); var builder = new StringBuilder(); if (log.AdditionalData.IsPrefixEnable) { builder.Append(log.MessagePrefix); builder.Append(":"); } if (log.AdditionalData.IsLevelEnable) { builder.Append("[" + log.AdditionalData.Level + "]"); builder.Append(":"); } builder.Append(log.Message); if (!string.IsNullOrEmpty(log.SubMessage)) { builder.Append($"({log.SubMessage})"); } if (log.AdditionalData.IsOccurenceTimeEnable) { builder.Append($"[{log.OccurrenceTime:yyyy-mm-dd hh:mm:ss}]"); } if (log.AdditionalData.IsTraceEnable) { builder.Append(newLineStrategy.NewLine); builder.Append(log.FormattedTrace); } return(builder.ToString()); }
public FileLogWriter(string filePath, INewLineStrategy newLineStrategy, IMessageFormatStrategy messageFormatStrategy) : base(new FileStream(filePath, FileMode.Create), newLineStrategy, messageFormatStrategy) { this.FilePath = filePath; }