public void Log <TState>( LogLevel logLevel, EventId eventId, TState state, Exception exception, Func <TState, Exception, string> formatter) { if (!IsEnabled(logLevel)) { return; } if (formatter == null) { throw new ArgumentNullException(nameof(formatter)); } var message = formatter(state, exception); if (string.IsNullOrEmpty(message)) { return; } if (exception != null) { message += $"\n{ exception.ToString() }"; } message = message.Length > MAXMESSAGELENGTH?message.Substring(0, MAXMESSAGELENGTH) : message; _loggerRepository.AddLog(new EventLog(eventId.Id, logLevel.ToString(), message)); }
public void Log(string type, string message) { try { using (var db = new LoggerContext(_conection)) { var repository = new LoggerRepository(db); repository.AddLog(type, message); } } catch (Exception ex) { // ignore } }
public void Log_SaveLog() { var mockSet = new Mock <DbSet <Log> >(); var mockContext = new Mock <LoggerContext>(string.Empty); mockContext.Setup(m => m.Logs).Returns(mockSet.Object); // Act var repository = new LoggerRepository(mockContext.Object); repository.AddLog("Error", "Test"); // Assert mockSet.Verify(m => m.Add(It.IsAny <Log>()), Times.Once); mockContext.Verify(m => m.SaveChanges(), Times.Once); }
public void LogInfo(string customMessage) { _db.AddLog(SeverityLevel.Info, string.Empty, string.Empty, customMessage); }