public static void FinishLog(CallClientMethodLogInformation log, object result) { if (isStop) { return; } if (log == null) { return; } log.ResultDateTime = DateTime.Now.ToLocalTime(); log.Result = result; log.CanWriteToFile = true; }
public static CallClientMethodLogInformation AddCallClientMethodLog(string sessionId, string ipAddress, DateTime connectedDateTime, string serviceName, string methodName, List <Models.ParameterInfo> parameters) { if (isStop) { return(null); } var log = new CallClientMethodLogInformation() { DateTime = DateTime.Now.ToLocalTime(), MethodName = methodName, Parameters = parameters, ServiceName = serviceName, ConnectedDateTime = connectedDateTime, IPAddress = ipAddress, SessionId = sessionId }; Logs.Enqueue(log); return(log); }
static void WriteToFile(CallClientMethodLogInformation log) { #if (NET35) string path = CombinePath(AutoLogger.ApplicationDirectory, "Logs", log.DateTime.Year.ToString(), log.DateTime.Month.ToString(), log.DateTime.Day.ToString()); #else string path = System.IO.Path.Combine(AutoLogger.ApplicationDirectory, "Logs", log.DateTime.Year.ToString(), log.DateTime.Month.ToString(), log.DateTime.Day.ToString()); #endif if (!System.IO.Directory.Exists(path)) { System.IO.Directory.CreateDirectory(path); } path = System.IO.Path.Combine(path, $"Callback-{log.DateTime.Year}-{log.DateTime.Month}-{log.DateTime.Day} {log.DateTime.ToLocalTime().Hour}.log"); StringBuilder build = new StringBuilder(); build.AppendLine("########################################"); build.AppendLine("Client Information:"); build.AppendLine($" Ip Address: {log.IPAddress}"); build.AppendLine($" SessionId: {log.SessionId}"); build.AppendLine($" Connected Time: {GetDateTimeString(log.ConnectedDateTime)}"); build.AppendLine(""); build.AppendLine($"Call Information:"); build.AppendLine($" Service Name: {log.ServiceName}"); build.Append($" Method: {log.MethodName}("); bool isFirst = true; int index = 1; foreach (var parameter in log.Parameters) { build.Append((isFirst ? "" : ",") + (parameter.Type == null ? "Null" : parameter.Type) + " obj" + index); isFirst = false; index++; } build.AppendLine(")"); build.AppendLine($" With Values:"); foreach (var parameter in log.Parameters) { build.AppendLine(" "+ (parameter.Value == null ? "Null" : JsonConvert.SerializeObject(parameter.Value, Formatting.None, new JsonSerializerSettings() { Formatting = Formatting.None }).Replace(@"\""", ""))); } build.AppendLine(""); build.AppendLine($"Result Information:"); build.AppendLine(" "+ (log.Result == null ? "Null" : JsonConvert.SerializeObject(log.Result, Formatting.None, new JsonSerializerSettings() { Formatting = Formatting.None })).Replace(@"\""", "")); build.AppendLine(""); build.AppendLine($"Invoked Time:"); build.AppendLine($" {GetDateTimeString(log.DateTime)}"); build.AppendLine($"Result Time:"); build.AppendLine($" {GetDateTimeString(log.ResultDateTime)}"); build.AppendLine("----------------------------------------------------------------------------------------"); build.AppendLine(""); using (var stream = new System.IO.FileStream(path, FileMode.OpenOrCreate, FileAccess.ReadWrite)) { stream.Seek(0, System.IO.SeekOrigin.End); byte[] bytes = Encoding.UTF8.GetBytes(build.ToString()); stream.Write(bytes, 0, bytes.Length); } }