public void Log <TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func <TState, Exception, string> formatter) { string log = LogFormatter.Handle <TState>(this.CategoryName, logLevel, eventId, state, exception, formatter); DateTime now = DateTime.Now; string fileName = now.ToString("yyyy-MM-dd") + ".log"; string path = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location); DirectoryInfo directory = new DirectoryInfo(Path.Combine(path, "logs")); fileLock.EnterWriteLock(); try { if (!directory.Exists) { directory.Create(); } this.ApplyRetainPolicy(directory); using (var writer = File.AppendText(Path.Combine(directory.FullName, fileName))) { writer.WriteLine(log); } } finally { fileLock.ExitWriteLock(); } }
public void Log <TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func <TState, Exception, string> formatter) { string d = Directory.GetCurrentDirectory(); if (!IsEnabled(logLevel)) { return; } if (_config.EventId == 0 || _config.EventId == eventId.Id) { var color = Console.ForegroundColor; Console.ForegroundColor = _config.Color; string msg = LogFormatter.Handle(_name, logLevel, eventId, state, exception, formatter); Console.WriteLine(msg); Console.ForegroundColor = color; } }