public async Task Add(LogEntry log) { try { var db = _client.GetDatabase("LoggingService"); var collection = db.GetCollection <LogEntryDto>("Logs"); await collection.InsertOneAsync(LogEntryDto.Parse(log)); } catch (Exception exception) { throw new InvalidProgramException("There was a problem inserting log entry.", exception); } }
public async Task <IEnumerable <LogEntry> > GetAll() { try { var db = _client.GetDatabase("LoggingService"); var collection = db.GetCollection <LogEntryDto>("Logs"); var documents = await collection.Find(Builders <LogEntryDto> .Filter.Empty).ToListAsync(); return(documents.Select(d => LogEntryDto.Parse(d))); } catch (Exception exception) { throw new InvalidProgramException("There was a problem getting all log entries.", exception); } }
public static LogEntry Parse(LogEntryDto log) => new LogEntry(log.Component, log.Message, log.Timestamp, log.Level);