public bool InsertLog(LogHeroi log) { var command = $@"INSERT INTO [dbo].[EventLog] ([LogLevel],[Message],[CreatedTime]) VALUES (@LogLevel, @Message, @CreatedTime)"; var paramList = new List <SqlParameter> { new SqlParameter("LogLevel", log.LogLevel), new SqlParameter("Message", log.Message), new SqlParameter("CreatedTime", log.CreatedTime) }; return(ExecuteNonQuery(command, paramList)); }
public void Log <TState>(LogLevel logLevel, EventId eventoId, TState state, Exception exception, Func <TState, Exception, string> formato) { if (!IsEnabled(logLevel)) { return; } if (formato == null) { throw new ArgumentNullException(nameof(formato)); } var mensagem = formato(state, exception); if (string.IsNullOrEmpty(mensagem)) { return; } if (exception != null) { mensagem += $"\n{exception.ToString()}"; } mensagem = mensagem.Length > _messageMaxLength?mensagem.Substring(0, _messageMaxLength) : mensagem; var heroLog = new LogHeroi() { Message = mensagem, LogLevel = logLevel.ToString(), CreatedTime = DateTime.UtcNow }; _repositorio.InsertLog(heroLog); }