public StreamCallMethodLogInformation AddStreamCallMethodLog(string clientId, string ipAddress, DateTime connectedDateTime, string serviceName, string methodName, SignalGo.Shared.Models.ParameterInfo[] parameters) { if (isStop) { return(null); } StreamCallMethodLogInformation log = new StreamCallMethodLogInformation() { DateTimeStartMethod = DateTime.Now.ToLocalTime(), MethodName = methodName, Parameters = parameters, ServiceName = serviceName, ConnectedDateTime = connectedDateTime, IPAddress = ipAddress, ClientId = clientId }; Logs.Enqueue(log); return(log); }
public void FinishLog(StreamCallMethodLogInformation log, string result) { if (isStop) { return; } if (log == null) { return; } log.DateTimeEndMethod = DateTime.Now.ToLocalTime(); if (log.Exception == null) { log.Result = result; } OnStreamServiceMethodCalledAction?.Invoke(log); log.CanWriteToFile = true; }
private void WriteToFile(StreamCallMethodLogInformation log) { #if (PORTABLE) throw new NotSupportedException(); #else #if (NET35) string path = CombinePath(AutoLogger.DirectoryLocation, "Logs", log.DateTimeStartMethod.Year.ToString(), log.DateTimeStartMethod.Month.ToString(), log.DateTimeStartMethod.Day.ToString()); #else string path = System.IO.Path.Combine(AutoLogger.DirectoryLocation, "Logs", log.DateTimeStartMethod.Year.ToString(), log.DateTimeStartMethod.Month.ToString(), log.DateTimeStartMethod.Day.ToString()); #endif if (!System.IO.Directory.Exists(path)) { System.IO.Directory.CreateDirectory(path); } path = System.IO.Path.Combine(path, $"Stream-{log.DateTimeStartMethod.Year}-{log.DateTimeStartMethod.Month}-{log.DateTimeStartMethod.Day} {log.DateTimeStartMethod.ToLocalTime().Hour}.log"); StringBuilder build = new StringBuilder(); build.AppendLine("########################################"); build.AppendLine("Client Information:"); build.AppendLine($" Ip Address: {log.IPAddress}"); build.AppendLine($" ClientId: {log.ClientId}"); build.AppendLine($" Connected Time: {GetDateTimeString(log.ConnectedDateTime)}"); build.AppendLine(""); build.AppendLine($"Call Information:"); build.AppendLine($" Service Name: {log.ServiceName}"); build.Append($" Method: {log.MethodName}"); //build.Append($" Method: {log.Method.Name}("); //bool isFirst = true; //foreach (var parameter in log.Method.GetParameters()) //{ // build.Append((isFirst ? "" : ",") + parameter.ParameterType.Name + " " + parameter.Name); // isFirst = false; //} //build.AppendLine(")"); if (log.Parameters != null) { build.AppendLine($" With Values:"); foreach (Shared.Models.ParameterInfo parameter in log.Parameters) { build.AppendLine(" "+ (parameter.Value == null ? "Null" : JsonConvert.SerializeObject(parameter.Value, Formatting.None, new JsonSerializerSettings() { Formatting = Formatting.None }).Replace(@"\""", ""))); } build.AppendLine(""); } if (log.Exception == null) { build.AppendLine($"Result Information:"); build.AppendLine(" "+ log.Result); build.AppendLine(""); } else { if (log.Exception != null) { build.AppendLine($"Exception:"); build.AppendLine(" "+ log.Exception.ToString()); build.AppendLine(""); } } build.AppendLine($"Invoked Time:"); build.AppendLine($" {GetDateTimeString(log.DateTimeStartMethod)}"); build.AppendLine($"Result Time:"); build.AppendLine($" {GetDateTimeString(log.DateTimeEndMethod)}"); build.AppendLine("----------------------------------------------------------------------------------------"); build.AppendLine(""); using (FileStream 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); } #endif }