Esempio n. 1
0
        public void SaveRequestAuditLog(HttpActionContext filterContext)
        {
            string requestParameter;

            using (var stream = filterContext.Request.Content.ReadAsStreamAsync().Result)
            {
                if (stream.CanSeek)
                {
                    stream.Position = 0;
                }
                requestParameter = filterContext.Request.Content.ReadAsStringAsync().Result;
            }
            AuditLogs auditLogs = new AuditLogs();

            auditLogs.Method           = filterContext.Request.Method.ToString();
            auditLogs.URL              = filterContext.Request.RequestUri.ToString();
            auditLogs.ControllerName   = filterContext.ControllerContext.ControllerDescriptor.ControllerName;
            auditLogs.Action           = filterContext.ActionDescriptor.ActionName;
            auditLogs.RequestParameter = JSONHelper.ToJSON(requestParameter);
            auditLogs.LogDate          = DataConversion.ConvertDateYMD(DateTime.Now.ToString());
            auditLogs.LogTime          = DateTime.Now.ToLongTimeString();

            var auditLogsDocs = new Document <AuditLogs>()
            {
                Id      = "Log_Request_" + DataConversion.ConvertYMDHMS(DateTime.Now.ToString()),
                Content = auditLogs
            };
            //WriteLog(auditLogs, "request");
            var result = _bucket.InsertAsync(auditLogsDocs);
        }
Esempio n. 2
0
        public void WriteLog(AuditLogs auditLogs, string type)
        {
            StringBuilder sb = new StringBuilder();

            if (type == "request")
            {
                sb.Append(DataConversion.ConvertYMDHMS(DateTime.Now.ToString()));
                sb.Append(Environment.NewLine);
                sb.Append("Method:" + " " + auditLogs.Method);
                sb.Append("Url:" + " " + auditLogs.URL);
                sb.Append("Controller:" + " " + auditLogs.ControllerName);
                sb.Append("Action:" + " " + auditLogs.Action);
                sb.Append("Request Parameter:" + " " + auditLogs.RequestParameter);
                sb.Append("LogDate:" + " " + DataConversion.ConvertDateYMD(DateTime.Now.ToString()));
                sb.Append("LogTime:" + " " + DateTime.Now.ToLongTimeString());
            }
            else
            {
                sb.Append("log something");
            }
            //File.AppendAllText(LogFilePath + DataConversion.ConvertDateYMD(DateTime.Now.ToShortDateString()) + "-api.txt", sb.ToString());
            sb.Clear();
        }