示例#1
0
        public CallMethodLogInformation AddCallMethodLog(string clientId, string ipAddress, DateTime connectedDateTime, string serviceName, MethodInfo method, SignalGo.Shared.Models.ParameterInfo[] parameters)
        {
            if (isStop)
            {
                return(null);
            }
            CallMethodLogInformation log = new CallMethodLogInformation()
            {
                DateTimeStartMethod = DateTime.Now.ToLocalTime(), Method = method, Parameters = parameters, ServiceName = serviceName, ConnectedDateTime = connectedDateTime, IPAddress = ipAddress, ClientId = clientId, MethodName = method?.Name
            };

            Logs.Enqueue(log);
            return(log);
        }
示例#2
0
 public void FinishLog(CallMethodLogInformation log, string result)
 {
     if (isStop)
     {
         return;
     }
     if (log == null)
     {
         return;
     }
     log.DateTimeEndMethod = DateTime.Now.ToLocalTime();
     if (log.Exception == null)
     {
         log.Result = result;
     }
     OnServiceMethodCalledAction?.Invoke(log);
     log.CanWriteToFile = true;
 }
示例#3
0
        private void WriteToFile(CallMethodLogInformation 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, $"{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.Method.Name}(");
            bool isFirst = true;
            foreach (ParameterInfo parameter in log.Method.GetParameters())
            {
                build.Append((isFirst ? "" : ",") + parameter.ParameterType.Name + " " + parameter.Name);
                isFirst = false;
            }
            build.AppendLine(")");

            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
            {
                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
        }