Example #1
0
        public HttpCallMethodLogInformation AddHttpMethodLog(string clientId, string ipAddress, DateTime connectedDateTime, string address, MethodInfo method, SignalGo.Shared.Models.ParameterInfo[] parameters)
        {
            if (isStop)
            {
                return(null);
            }
            HttpCallMethodLogInformation log = new HttpCallMethodLogInformation()
            {
                DateTimeStartMethod = DateTime.Now.ToLocalTime(), Method = method, Parameters = parameters, Address = address, ConnectedDateTime = connectedDateTime, IPAddress = ipAddress, ClientId = clientId, MethodName = method?.Name
            };

            Logs.Enqueue(log);
            return(log);
        }
Example #2
0
 public void FinishLog(HttpCallMethodLogInformation log, string result)
 {
     if (isStop)
     {
         return;
     }
     if (log == null)
     {
         return;
     }
     log.DateTimeEndMethod = DateTime.Now.ToLocalTime();
     if (log.Exception == null)
     {
         log.Result = result;
     }
     OnHttpServiceMethodCalledAction?.Invoke(log);
     log.CanWriteToFile = true;
 }
Example #3
0
        private void WriteToFile(HttpCallMethodLogInformation 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, $"HTTP-{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($"	Address:	{log.Address}");
            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(")");
            if (log.Parameters != null)
            {
                build.AppendLine($"	With Values:");
                foreach (Shared.Models.ParameterInfo value in log.Parameters)
                {
                    build.AppendLine("			"+ (value == null || string.IsNullOrEmpty(value.Name) ? "Null" : value.Name));
                }
                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($"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
        }