Example #1
0
        static void WriteToFile(HttpCallMethodLogInformation 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, $"HTTP-{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($"	Address:	{log.Address}");
            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(")");

            build.AppendLine($"	With Values:");
            foreach (var value in log.Parameters)
            {
                build.AppendLine("			"+ (value == null ? "Null" : value));
            }
            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("			"+ (log.Result == null ? "Null" : log.Result.GetType().FullName));
            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);
            }
        }
Example #2
0
 public static void FinishLog(HttpCallMethodLogInformation log, object result)
 {
     if (isStop)
     {
         return;
     }
     if (log == null)
     {
         return;
     }
     log.ResultDateTime = DateTime.Now.ToLocalTime();
     log.Result         = result;
     log.CanWriteToFile = true;
 }
Example #3
0
        public static HttpCallMethodLogInformation AddHttpMethodLog(string sessionId, string ipAddress, DateTime connectedDateTime, string address, MethodInfo method, List <string> parameters)
        {
            if (isStop)
            {
                return(null);
            }
            var log = new HttpCallMethodLogInformation()
            {
                DateTime = DateTime.Now.ToLocalTime(), Method = method, Parameters = parameters, Address = address, ConnectedDateTime = connectedDateTime, IPAddress = ipAddress, SessionId = sessionId
            };

            Logs.Enqueue(log);
            return(log);
        }