public void SqlTraceLog_Verbose_ReturnsOk()
        {
            // Arrange
            var controller = new LogController();
            var logEntry   = new SQLTraceLogModel
            {
                LogLevel   = LogLevelEnum.Verbose,
                Source     = "Controller source",
                Message    = "Hello",
                OccurredAt = DateTime.Now
            };

            // Act
            var result = controller.Log(logEntry);

            // Assert
            Assert.IsInstanceOfType(result, typeof(OkResult));
        }
Beispiel #2
0
        public async Task LogSQLTraceLog_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 SQLTraceLogModel()
            {
                Source   = "ServiceLogRepositoryTests",
                LogLevel = LogLevelEnum.Informational,
                Message  = "Hello World",
                UserName = "******"
            };

            // Act
            await servicelog.LogSQLTraceLog(logEntry);

            // Assert
            // Doesn't return anything
        }
        public async Task LogSQLTraceLog(SQLTraceLogModel 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/sqltracelog", content);

                response.EnsureSuccessStatusCode();
            }
            catch (Exception ex)
            {
                _localLog.LogErrorFormat("Problem with ConfigControl Log service: {0}", ex.Message);
            }
        }
Beispiel #4
0
        public IHttpActionResult Log([FromBody] SQLTraceLogModel logEntry)
        {
            string ipAdress = GetIpAddress();

            SQLTraceLogEventSource.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,
                logEntry.TextData,
                logEntry.SPID,
                logEntry.Database);

            return(Ok());
        }