// [Route("salt")] // [HttpGet] // public GetLearnerInfoResponse salt(string token) // { // try // { // // var aa= Request.Headers["Content-Type"]; // if (string.IsNullOrEmpty(token)) // { // return new GetLearnerInfoResponse // { // StatusCode = Global.Status[responseCode.TokenError].StatusCode, // Description = Global.Status[responseCode.TokenError].Description // }; // } // var key = "2cff5601e52f4747bfb9e271fe45042a"; // var salt = "d31beaac47b44b45b1c6066712d49ff6"; // var original_value = token; // var encrypted_value = CryptographyHelpers.Encrypt(key, salt, original_value); // var target = CryptographyHelpers.Decrypt(key, salt, encrypted_value); // return new GetLearnerInfoResponse // { // Name = encrypted_value, // // Identity = encrypted_value.Length.ToString(), // StatusCode = encrypted_value.Length.ToString(), // Description = target, // }; // } // catch (Exception ex) // { // return new GetLearnerInfoResponse // { // StatusCode = Global.Status[responseCode.ProgramError].StatusCode, // Description = Global.Status[responseCode.ProgramError].Description + ex.Message // }; // } // } private async void LogRequest(string content, string method = null, string ip = null) { try { var to = GetToken(); // Log.Information("LogRequest,{0},from ip={1}",to+ ", begin", Request.HttpContext.Connection.RemoteIpAddress); // await Task.Delay(5000); Log.Information("LogRequest,{0},from ip={1}", to + ", 000", Request.HttpContext.Connection.RemoteIpAddress); var dbtext = string.Empty; var dbmethod = string.Empty; var dbip = string.Empty; var contentlenth = 150; var shortlength = 44; if (!string.IsNullOrEmpty(content)) { var lenth = content.Length; dbtext = lenth > contentlenth?content.Substring(0, contentlenth) : content; } if (!string.IsNullOrEmpty(method)) { dbmethod = method.Length > shortlength?method.Substring(0, shortlength) : method; } if (!string.IsNullOrEmpty(ip)) { dbip = ip.Length > shortlength?ip.Substring(0, shortlength) : ip; } await Task.Run(() => { Log.Information("LogRequest,{0},from ip={1}", to + ", 111", Request.HttpContext.Connection.RemoteIpAddress); using (var logdb = new blahContext()){ for (int i = 0; i < 1000; i++) { logdb.Request.Add( new Request { Content = i.ToString(), Ip = dbip, Method = dbmethod, Time = DateTime.Now } ); } logdb.SaveChanges(); } Log.Information("LogRequest,{0},from ip={1}", to + ", 222", Request.HttpContext.Connection.RemoteIpAddress); // await Task.Delay(2000); // Log.Information("LogRequest,{0},from ip={1}", to+", 333", Request.HttpContext.Connection.RemoteIpAddress); }); Log.Information("LogRequest,{0},from ip={1}", to + ", end", Request.HttpContext.Connection.RemoteIpAddress); } catch (Exception ex) { Log.Information("LogRequest error,{0},from ip={1}", ex.Message, Request.HttpContext.Connection.RemoteIpAddress); } }
private async void LogRequest(string content, string method = null, string ip = null, short businessType = 0) { var dbtext = string.Empty; var dbmethod = string.Empty; var dbip = string.Empty; var contentlenth = 150; var shortlength = 44; if (!string.IsNullOrEmpty(content)) { var lenth = content.Length; dbtext = lenth > contentlenth?content.Substring(0, contentlenth) : content; } if (!string.IsNullOrEmpty(method)) { dbmethod = method.Length > shortlength?method.Substring(0, shortlength) : method; } if (!string.IsNullOrEmpty(ip)) { dbip = ip.Length > shortlength?ip.Substring(0, shortlength) : ip; } await Task.Run(() => { using (var logdb = new blahContext()) { logdb.Request.Add(new Request { Content = dbtext, Businesstype = businessType, Ip = dbip, Method = dbmethod, Time = DateTime.Now }); logdb.SaveChanges(); } }); }