public void getInput(string one, string two, string _operator, InterfaceLog e) { log = e; this.first = Double.Parse(one); this.second = Double.Parse(two); switch (_operator) { case "+": case "-add": operator1 = "+"; break; case "-": case "-minus": operator1 = "-"; break; case "*": case "-multiply": operator1 = "*"; break; case "/": case "-divide": operator1 = "/"; break; default: Console.WriteLine("You can't calculate because operator is incorrect."); break; } }
public Server(InterfaceLog logger) { server = new TcpListener(IPAddress.Any, 9999); messages = new Queue <Message>(); people = new Dictionary <int, Client>(); UserIDNumber = 0; this.logger = logger; server.Start(); }
/// <summary> /// 记录接口日志到数据库 /// </summary> /// <param name="interfaceName"></param> /// <param name="request"></param> /// <param name="response"></param> /// <param name="flag"></param> /// <returns></returns> public BllResult <int?> LogInterface(string interfaceName, string request, string response, LogLevel flag, string content, string remark) { InterfaceLog interfaceLog = new InterfaceLog(); interfaceLog.InterfaceName = interfaceName; interfaceLog.Request = request; interfaceLog.Response = response; interfaceLog.Flag = flag.ToString(); interfaceLog.Content = content; interfaceLog.Remark = remark; interfaceLog.CreatedBy = Accounts.WCSInterface.ToString(); interfaceLog.Created = DateTime.Now; return(AppSession.Dal.InsertCommonModel <InterfaceLog>(interfaceLog)); }
public async Task InsertSystemLogAsync(SystemLog systemLog) { try { using (var context = new StandardcanContext()) { InterfaceLog interfaceLog = new InterfaceLog(); interfaceLog.Module = systemLog.module; interfaceLog.UpdateDate = DateTime.Now; interfaceLog.DataLog = systemLog.data_log; await context.InterfaceLog.AddAsync(interfaceLog); await context.SaveChangesAsync(); } } catch (Exception ex) { throw new Exception(ex.Message); } }
public void getInput(string one, string two, string _operator,InterfaceLog e) { log = e; this.first = Double.Parse(one); this.second = Double.Parse(two); switch (_operator) { case "+": case "-add": operator1 = "+"; break; case "-": case "-minus": operator1 = "-"; break; case "*": case "-multiply": operator1 = "*"; break; case "/": case "-divide": operator1 = "/"; break; default: Console.WriteLine("You can't calculate because operator is incorrect."); break; } }
/// <summary> /// 构造响应消息日志 /// </summary> /// <param name="actionExecutedContext"></param> public static void BuildResponseLog(this HttpActionExecutedContext actionExecutedContext) { var logFlag = actionExecutedContext.ActionContext.ActionDescriptor.GetCustomAttributes <WriteLogAttribute>(); if (logFlag == null || logFlag.Count == 0) { return; } var request = actionExecutedContext.Request; var response = actionExecutedContext.Response; if (response == null) { // not log when the response is null. return; } DateTime startTime; if (!request.TryGetPropertyValue <DateTime>( ApiConstants.StartInterfaceTime, out startTime)) { return; } // 接口调用日志 InterfaceLog log = new InterfaceLog(); log.ApplicationName = "Smart.API.Adapter.Api"; log.ServerName = Environment.MachineName; log.IPAddress = HttpContext.Current.Request.UserHostAddress; log.InterfaceName = actionExecutedContext.ActionContext.GetApiName(); log.MethodName = actionExecutedContext.ActionContext.ActionDescriptor.ActionName; log.RequestTime = startTime; log.ResponseTime = DateTime.Now; string requestContent = "", responseContent = ""; if (request.Content != null) { if (request.Content.IsMimeMultipartContent()) { requestContent = "---request with multipart/form-data only log the form data---" + "\r\n\r\n" + HttpContext.Current.Request.Form.ToString(); } else { using (var stream = request.Content.ReadAsStreamAsync().Result) { stream.Seek(0, System.IO.SeekOrigin.Begin); using (var reader = new System.IO.StreamReader(stream)) { requestContent = reader.ReadToEnd(); } } } } if (actionExecutedContext.Response.Content != null) { responseContent = response.Content.ReadAsStringAsync().Result; } log.RequestContent = String.Format(CultureInfo.InvariantCulture, "HTTP {0} {1}{2}", request.Method.Method, request.RequestUri.ToString(), string.IsNullOrEmpty(requestContent) ? "" : "\r\n" + requestContent); log.ResponseContent = String.Format(CultureInfo.InvariantCulture, "{0} {1}\r\n{2}", ((int)response.StatusCode).ToString(), response.StatusCode.ToString(), responseContent); //Logger.TryLog(log); //写日志 if (CommonSettings.LogType == "1") { LogHelper.Info(log.ToJson()); } }