private int InitialLog(string method, string request, string contentType, IHeaderDictionary header, string ods)
        {
            int id = -1;

            string headers = GetHeaders(header);

            using (Repository.PicasoActivityLogContext context = new Repository.PicasoActivityLogContext())
            {
                var sw = new Stopwatch();
                sw.Start();
                var log = new Repository.RabbitHoleLog();
                // Request
                log.Method       = method;
                log.Request      = request;
                log.ContentType  = contentType;
                log.PicasoHeader = headers;
                log.ODS          = ods;
                log.Timestamp    = DateTime.UtcNow;
                log.Duration     = -1;
                log.StatusCode   = -1;
                context.RabbitHoleLog.Add(log);
                context.SaveChanges();
                id = log.id;
            }

            return(id);
        }
        private bool UpdateLog(int id, int statusCode, string message, string exception)
        {
            bool result = false;

            using (Repository.PicasoActivityLogContext context = new Repository.PicasoActivityLogContext())
            {
                // Response
                var theLog = context.RabbitHoleLog.FirstOrDefault(item => item.id == id);
                if (theLog != null)
                {
                    TimeSpan ts = DateTime.UtcNow - theLog.Timestamp;
                    theLog.StatusCode = statusCode;
                    theLog.Message    = message;
                    theLog.Duration   = Math.Round((ts.TotalMilliseconds / 1000), 4);
                    context.SaveChanges();
                }
            }

            return(result);
        }
        private bool UpdateLog(int id, string contentType, XmlNode statusCodeNode, XmlNode bodyNode, string exception)
        {
            bool result = false;

            int statusCode = -1;

            if (statusCodeNode != null)
            {
                int.TryParse(statusCodeNode.InnerText, out statusCode);
            }

            string message = null;

            if (contentType == "application/json" || contentType == "text/plain")
            {
                if (bodyNode != null && (statusCode == 400 || statusCode == 401 || statusCode == 500))
                {
                    message = bodyNode.InnerText;
                }
            }

            using (Repository.PicasoActivityLogContext context = new Repository.PicasoActivityLogContext())
            {
                // Response
                var theLog = context.RabbitHoleLog.FirstOrDefault(item => item.id == id);
                if (theLog != null)
                {
                    TimeSpan ts = DateTime.UtcNow - theLog.Timestamp;
                    theLog.StatusCode = statusCode;
                    theLog.Message    = message;
                    theLog.Duration   = Math.Round((ts.TotalMilliseconds / 1000), 4);
                    context.SaveChanges();
                }
            }

            return(result);
        }