private bool MessageContains(LogMessageV1 message, string search) { if (MatchString(message.Message, search)) { return(true); } if (MatchString(message.Correlation_Id, search)) { return(true); } if (message.Error != null) { if (MatchString(message.Error.Message, search)) { return(true); } if (MatchString(message.Error.StackTrace, search)) { return(true); } if (MatchString(message.Error.Code, search)) { return(true); } } return(false); }
public void It_Should_Read_Messages_Async() { var initialLogMessages = new LogMessageV1[] { Model.SampleMessage1, Model.SampleErrorMessage1 }; _moqLoggingPersistence.Setup(p => p.GetPageByFilterAsync(Model.CorrelationId, null, null)).Returns(Task.FromResult(initialLogMessages)); var resultLogMessages = _loggingController.ReadMessagesAsync(Model.CorrelationId, null, null).Result; Assert.Equal(initialLogMessages.Length, resultLogMessages.Length); }
public void It_Should_Create_Log_Message_V1() { LogLevel level = default(Commons.Log.LogLevel); string source = "Test Source"; string correlationId = "Test Correlation ID"; ErrorDescription error = new ErrorDescription(); string message = "Test Message"; var logMessage = new LogMessageV1(level, source, correlationId, error, message); Assert.Equal(level, logMessage.Level); Assert.Equal(source, logMessage.Source); Assert.Equal(correlationId, logMessage.Correlation_Id); Assert.Equal(error, logMessage.Error); Assert.Equal(message, logMessage.Message); }
public Task CreateAsync(string correlationId, LogMessageV1 message) { return(Task.Run(() => { // Add to all messages TruncateMessages(Messages, MaxTotalSize); InsertMessage(message, Messages); // Add to errors separately if (message.Level <= LogLevel.Error) { TruncateMessages(ErrorMessages, MaxErrorSize); InsertMessage(message, ErrorMessages); } })); }
public void It_Should_Read_Errors_Async() { var initialLogMessages = new LogMessageV1[] { Model.SampleMessage1, Model.SampleErrorMessage1 }; var initialErrorMessages = initialLogMessages.Where(m => m.Level <= LogLevel.Error).ToArray(); var filter = new FilterParams(); filter.SetAsObject("errors_only", true); _moqLoggingPersistence.Setup(p => p.GetPageByFilterAsync(Model.CorrelationId, filter, null)).Returns(Task.FromResult(initialErrorMessages)); _moqLoggingPersistence.Setup(p => p.GetPageByFilterAsync(Model.CorrelationId, null, null)).Returns(Task.FromResult(initialLogMessages)); var resultLogMessages = _loggingController.ReadErrorsAsync(Model.CorrelationId, null, null).Result; Assert.Equal(initialErrorMessages.Length, resultLogMessages.Length); }
static void Main(string[] args) { try { var correlationId = "123"; var config = ConfigParams.FromTuples( "connection.type", "http", "connection.host", "localhost", "connection.port", 8080 ); var client = new LoggingHttpClientV1(); client.Configure(config); LogMessageV1 message1 = new LogMessageV1() { Time = new DateTime(), Source = null, Level = LogLevel.Debug, CorrelationId = "123", Error = null, Message = "BBB" }; LogMessageV1 message2 = new LogMessageV1() { Time = new DateTime(), Source = null, Level = LogLevel.Error, CorrelationId = "123", Error = ErrorDescriptionFactory.Create(new Exception()), Message = "AAB" }; client.OpenAsync(correlationId); client.WriteMessagesAsync(null, new LogMessageV1[] { message1, message2 }); var page = client.ReadMessagesAsync(null, FilterParams.FromTuples("search", "AA"), null); Console.WriteLine("Read log messages: "); Console.WriteLine("Press ENTER to exit..."); Console.ReadLine(); client.CloseAsync(string.Empty); } catch (Exception ex) { Console.WriteLine(ex); } }
public async Task TestCrudOperationsAsync() { var message = await this._client.WriteMessageAsync(null, new LogMessageV1() { Time = new DateTime(), Source = null, Level = LogLevel.Info, CorrelationId = "123", Error = null, Message = "AAA" }); Assert.NotNull(message); var message1 = new LogMessageV1() { Time = new DateTime(), Source = null, Level = LogLevel.Debug, CorrelationId = "123", Error = null, Message = "BBB" }; var message2 = new LogMessageV1() { Time = new DateTime(), Source = null, Level = LogLevel.Error, CorrelationId = "123", Error = ErrorDescriptionFactory.Create(new Exception()), Message = "AAB" }; message2.Time = new DateTime(1975, 1, 1, 0, 0, 0, 0); await this._client.WriteMessagesAsync(null, new LogMessageV1[] { message1, message2 }); var page = await this._client.ReadMessagesAsync(null, FilterParams.FromTuples("search", "AA"), null); Assert.Equal(2, page.Data.Count); page = await this._client.ReadErrorsAsync(null, null, null); Assert.Single(page.Data); }
private void InsertMessage(LogMessageV1 message, IList <LogMessageV1> messages) { var index = 0; // Find index to keep messages sorted by time while (index < messages.Count) { if (message.Time >= messages[index].Time) { break; } index++; } messages.Insert(index < messages.Count ? index : 0, message); }
public void It_Should_Read_Messages_Async() { var initialLogMessages = new LogMessageV1[] { Model.SampleMessage1, Model.SampleErrorMessage1 }; _moqLoggingController.Setup(c => c.ReadMessagesAsync(Model.CorrelationId, Model.FilterParams, Model.PagingParams)) .Returns(Task.FromResult(initialLogMessages)); var resultContent = SendPostRequest("read_messages", new { correlation_id = Model.CorrelationId, filter = Model.FilterParams, paging = Model.PagingParams }); var resultLogMessages = JsonConverter.FromJson <LogMessageV1[]>(resultContent); Assert.Equal(initialLogMessages.Length, resultLogMessages.Length); }
public TestModel() { MaxPageSize = 20; MaxErrorSize = 50; MaxTotalSize = 100; ConfigParams = new ConfigParams { { "options.max_page_size", MaxPageSize.ToString() }, { "options.max_error_size", MaxErrorSize.ToString() }, { "options.max_total_size", MaxTotalSize.ToString() } }; CorrelationId = "1"; FiveDaysAgo = DateTime.UtcNow.AddDays(-5); FourDaysAgo = DateTime.UtcNow.AddDays(-4); ThreeDaysAgo = DateTime.UtcNow.AddDays(-3); TwoDaysAgo = DateTime.UtcNow.AddDays(-2); OneDayAgo = DateTime.UtcNow.AddDays(-1); SampleMessage1 = new LogMessageV1(FiveDaysAgo, LogLevel.Info, "Persistence", CorrelationId, null, "Test Message #1"); SampleMessage2 = new LogMessageV1(ThreeDaysAgo, LogLevel.Warn, "Persistence", CorrelationId, null, "Test Message #2"); SampleMessage3 = new LogMessageV1(OneDayAgo, LogLevel.Debug, "Persistence", CorrelationId, null, "Test Message #3"); SampleErrorMessage1 = new LogMessageV1(FiveDaysAgo, LogLevel.Error, "Persistence", CorrelationId, new ErrorDescription() { Code = "911" }, "Test Error Message #1"); SampleErrorMessage2 = new LogMessageV1(ThreeDaysAgo, LogLevel.Fatal, "Persistence", CorrelationId, new ErrorDescription() { }, "Test Error Message #2"); SampleErrorMessage3 = new LogMessageV1(OneDayAgo, LogLevel.Fatal, "Persistence", CorrelationId, new ErrorDescription() { Cause = "Bad luck" }, "Test Error Message #3"); FilterParams = new FilterParams(); PagingParams = new PagingParams(); }
public Task WriteMessageAsync(string correlationId, LogMessageV1 message) { return(WritePersistence.CreateAsync(correlationId, message)); }
public Task CreateAsync(string correlationId, LogMessageV1 message) { throw new NotImplementedException(); }