/// <summary>
        ///     Deletes a log item
        /// </summary>
        /// <param name="log">Log item</param>
        public virtual void DeleteLog(LogRecord log)
        {
            if (log == null)
                throw new ArgumentNullException("log");

            _logRepository.Delete(log);
        }
        public void DbLogger_WriteToDatabase()
        {
            var logRecordList = new List<LogRecord>();
            var repositoryMock = new Mock<IRepository<LogRecord>>();
            repositoryMock
                .Setup(r => r.Insert(It.IsAny<LogRecord>()))
                .Callback<LogRecord>(lr => logRecordList.Add(lr));

            var fakeCommonSettings = new FakeCommonSettings();

            var dbLogger = new DbLogger(repositoryMock.Object, fakeCommonSettings);
            var expected = new LogRecord
            {
                LogLevel = LogLevel.Debug,
                ShortMessage = "shortMessage",
                FullMessage = "fullMessage"
            };

            dbLogger.InsertLogRecord(expected.LogLevel, expected.ShortMessage, expected.FullMessage);

            Assert.Equal(1, logRecordList.Count);

            var actual = logRecordList[0];
            expected.FullMessage.ShouldEqual(actual.FullMessage);
            expected.ShortMessage.ShouldEqual(actual.ShortMessage);
            expected.LogLevel.ShouldEqual(actual.LogLevel);

        }
Exemple #3
0
        public LogRecord InsertLogRecord(LogLevel logLevel, string shortMessage, string fullMessage = "", IDictionary<object, object> extraData = null)
        {
            //check ignore word/phrase list?
            if (IgnoreLog(shortMessage) || IgnoreLog(fullMessage))
                return null;

            var log = new LogRecord
            {
                LogLevel = logLevel,
                ShortMessage = shortMessage,
                FullMessage = fullMessage,
                CreatedOnUtc = DateTime.UtcNow
            };

            _logRepository.Insert(log);

            return log;
        }