public void PerformanceLog_Verbose_ReturnsOk() { // Arrange var controller = new LogController(); var logEntry = new PerformanceLogModel { LogLevel = LogLevelEnum.Verbose, Source = "Controller source", Message = "Hello", OccurredAt = DateTime.Now }; // Act var result = controller.Log(logEntry); // Assert Assert.IsInstanceOfType(result, typeof(OkResult)); }
public async Task LogPerformanceLog_Success() { // Arrange var httpClientProvider = new TestHttpClientProvider(request => new HttpResponseMessage(HttpStatusCode.OK)); var localLog = new Mock <ILocalLog>().Object; var servicelog = new ServiceLogRepository(httpClientProvider, localLog); var logEntry = new PerformanceLogModel() { Source = "ServiceLogRepositoryTests", LogLevel = LogLevelEnum.Informational, Message = "Hello World", UserName = "******" }; // Act await servicelog.LogPerformanceLog(logEntry); // Assert // Doesn't return anything }
public IHttpActionResult Log([FromBody] PerformanceLogModel logEntry) { string ipAdress = GetIpAddress(); PerformanceLogEventSource.Log.Verbose( ipAdress, logEntry.Source, logEntry.Message, logEntry.OccurredAt, logEntry.SessionId, logEntry.UserName, logEntry.ThreadID, logEntry.ActionName, logEntry.CorrelationId, logEntry.Duration, logEntry.Namespace, logEntry.Class, logEntry.Test); return(Ok()); }
public async Task LogPerformanceLog(PerformanceLogModel logEntry) { try { var uri = _configControlUri; if (string.IsNullOrWhiteSpace(uri)) { throw new ApplicationException("Application setting not set: ConfigControl"); } var http = _httpClientProvider.Create(new Uri(uri)); // Convert Object to JSON var requestMessage = JsonConvert.SerializeObject(logEntry); var content = new StringContent(requestMessage, Encoding.UTF8, "application/json"); HttpResponseMessage response = await http.PostAsync(@"log/performancelog", content); response.EnsureSuccessStatusCode(); } catch (Exception ex) { _localLog.LogErrorFormat("Problem with ConfigControl Log service: {0}", ex.Message); } }