private bool sendToLog(WebLogModel logMetadata) { Log log = new Log(); log.Save(logMetadata); return(true); }
private WebLogModel buildResponseMetadata(WebLogModel logMetadata, HttpResponseMessage response) { logMetadata.ResponseTime = DateTime.Now; logMetadata.ResponseStatusCode = response.StatusCode; if (response.Content != null) { logMetadata.ResponseHeaders = response.Content.Headers; logMetadata.ResponseContentText = (response.Content != null) ?response.Content.ReadAsStringAsync().Result:string.Empty; } logMetadata.ResponseVersion = response.Version; return(logMetadata); }
public void Save(WebLogModel logModel) { SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["WebLogDB"].ConnectionString); SqlCommand cmd = new SqlCommand("WebLog_Add", conn); cmd.CommandType = System.Data.CommandType.StoredProcedure; try { cmd.Parameters.AddWithValue("@ID", logModel.ID); cmd.Parameters["@ID"].Direction = System.Data.ParameterDirection.Output; cmd.Parameters.AddWithValue("@RequestContent", logModel.RequestContentText); cmd.Parameters.AddWithValue("@RequestHeaders", logModel.RequestHeadersText); cmd.Parameters.AddWithValue("@RequestMethod", logModel.RequestMethodText); cmd.Parameters.AddWithValue("@RequestTime", logModel.RequestTime); cmd.Parameters.AddWithValue("@Scheme", logModel.SchemeText); cmd.Parameters.AddWithValue("@Site", logModel.SiteText); cmd.Parameters.AddWithValue("@Path", logModel.PathText); cmd.Parameters.AddWithValue("@Query", logModel.QueryText); cmd.Parameters.AddWithValue("@RequestClientIP", logModel.RequestClientIP); cmd.Parameters.AddWithValue("@RequestHost", logModel.RequestHost); cmd.Parameters.AddWithValue("@Uri", logModel.RequestUriText); cmd.Parameters.AddWithValue("@RequestVersion", logModel.RequestVersionText); cmd.Parameters.AddWithValue("@ResponseContent", logModel.ResponseContentText); cmd.Parameters.AddWithValue("@ResponseHeaders", logModel.ResponseHeadersText); cmd.Parameters.AddWithValue("@StatusCode", logModel.ResponseStatusCodeText); cmd.Parameters.AddWithValue("@ResponseTime", logModel.ResponseTime); cmd.Parameters.AddWithValue("@ResponseVersion", logModel.ResponseVersionText); cmd.Parameters.AddWithValue("@Queries", getQueries(logModel.QueryText)); cmd.Parameters["@Queries"].SqlDbType = SqlDbType.Structured; conn.Open(); cmd.ExecuteNonQuery(); logModel.ID = long.Parse(cmd.Parameters["@ID"].Value.ToString()); } finally { conn.Close(); conn.Dispose(); conn = null; cmd.Dispose(); cmd = null; } }
private WebLogModel buildRequestMetadata(HttpRequestMessage request) { WebLogModel log = new WebLogModel { RequestTime = DateTime.Now, RequestUri = request.RequestUri, RequestMethod = request.Method, RequestHeaders = request.Headers, RequestContentText = (request.Content != null)?request.Content.ReadAsStringAsync().Result:string.Empty, RequestContentHeaders = request.Content.Headers, RequestVersion = request.Version, RequestClientIP = request.GetClientIpAddress() }; return(log); }