//public static List<AppsLog> GetLog(DateTime dateBegin, DateTime dateEnd, string exceptions) //{ // string dates = string.Format("[\"{0}\", \"{1}\"]",dateBegin.ToString("yyyy-MM-dd"), dateEnd.ToString("yyyy-MM-dd")); // Dictionary<string, string> arrParam = new Dictionary<string, string> { // {"dates", dates }, // {"exceptions", exceptions } // }; // string url = WebRequestUtils.GetPathToAddParam(Constants.PathToLog, arrParam); // ContentAndHeads contentAndHeads = WebRequestUtils.GetJsonAndHeads (url); // string json = contentAndHeads.Content[0]; // List<AppsLog> arrLogs = new List<AppsLog>(); // arrLogs.AddRange (JsonConvert.DeserializeObject<List<AppsLog>> (json)); // return arrLogs; //} //public static void AddLog(AppsLog log) //{ // Dictionary<string, string> arrParam = new Dictionary<string, string> { // {"system_name", log.SystemName }, // {"device_model", log.DeviceModel }, // {"system_version", log.SystemVersion }, // {"exception_type", log.ExceptionType }, // {"stack_trace", log.StackTrace }, // {"message", log.Message }, // {"additional_data", log.AdditionalData }, // }; // string url = Constants.PathToLog; // string data = string.Join ("&", arrParam.Select (x => x.Key + "=" + x.Value)); // WebRequestUtils.GetJsonAndHeads (url, "POST", data); //} public static async void AddLogAsync(AppsLog log) { Dictionary <string, string> arrParam = new Dictionary <string, string> { { "system_name", log.SystemName }, { "device_model", log.DeviceModel }, { "system_version", log.SystemVersion }, { "exception_type", log.ExceptionType }, { "stack_trace", log.StackTrace }, { "message", log.Message }, { "additional_data", log.AdditionalData }, }; string url = Constants.PathToLog; string data = string.Join("&", arrParam.Select(x => x.Key + "=" + x.Value)); await WebRequestUtils.GetJsonAndHeadsAsync(url, "POST", data); }
public static async void SendLog(AppsLog appsLog) { Dictionary <string, string> dicLog = new Dictionary <string, string>() { { "system_name", appsLog.SystemName }, { "device_model", appsLog.DeviceModel }, { "system_version", appsLog.SystemVersion }, { "exception_type", appsLog.ExceptionType }, { "stack_trace", appsLog.StackTrace }, { "message", appsLog.Message }, { "additional_data", appsLog.AdditionalData }, { "page_history", appsLog.PageHistory }, { "app_version", appsLog.AppVersion }, { "app_function", appsLog.AppFunction }, { "size_memory", appsLog.SizeMemory }, { "type_error", appsLog.TypeError }, { "user_id", appsLog.UserId.ToString() }, { "user_key", appsLog.UseKey }, { "url", appsLog.UrlApp }, { "url_data", appsLog.UrlData }, { "url_method", appsLog.UrlMethod }, }; string data = DictionaryToPostString(dicLog); string url = Constants.PathToLog; ContentAndHeads contentAndHeads = null; contentAndHeads = await WebRequestUtils.GetJsonAndHeadsAsync(url, "POST", data, true); if (contentAndHeads.requestStatus != HttpStatusCode.OK && contentAndHeads.requestStatus != HttpStatusCode.Created) { throw new Exception(); } }
static void SendLog(WebException ex, string messResult, string method, string url, string data) { // string method = request.Method; // string url = request.RequestUri.OriginalString; // string data = null; if (method == "GET") { data = null; } string message; if (ex.Response != null) { message = messResult; } //message = new StreamReader(ex.Response.GetResponseStream()).ReadToEnd(); else { message = ex.Message; } string methodShow = null; string exClass = null; if (ex.TargetSite != null) { methodShow = ex.TargetSite.Name; exClass = ex.TargetSite.DeclaringType.FullName; } string pageHistory; if (OnePage.redirectApp != null) { pageHistory = OnePage.redirectApp.GetHistoryToJson(); } else { pageHistory = "нету"; } AppsLog log = new AppsLog { SystemName = Device.OS.ToString(), ExceptionType = ex.GetType().ToString(), StackTrace = ex.StackTrace, Message = message, AdditionalData = @""" """, PageHistory = pageHistory, AppVersion = App.Version, AppFunction = exClass + "." + methodShow, TypeError = "TypeWeb", UserId = User.Singleton == null ? 0 : User.Singleton.Id, UseKey = User.Singleton?.HashKey, UrlApp = url, UrlMethod = method, UrlData = data }; #if __ANDROID__ var activityManager = Android.App.Application.Context.GetSystemService(Android.App.Activity.ActivityService) as Android.App.ActivityManager; Android.App.ActivityManager.MemoryInfo memoryInfo = new Android.App.ActivityManager.MemoryInfo(); activityManager.GetMemoryInfo(memoryInfo); double totalUsed = memoryInfo.AvailMem / (1024 * 1024); double totalRam = memoryInfo.TotalMem / (1024 * 1024); log.DeviceModel = Android.OS.Build.Model; log.SystemVersion = Android.OS.Build.VERSION.Sdk; log.SizeMemory = totalUsed.ToString("f2") + "/" + totalRam.ToString("f2"); #elif __IOS__ log.DeviceModel = UIKit.UIDevice.CurrentDevice.Name; log.SystemVersion = UIKit.UIDevice.CurrentDevice.SystemVersion; log.SizeMemory = (Foundation.NSProcessInfo.ProcessInfo.PhysicalMemory / (1024 * 1024)).ToString("f2"); #endif AppsLog.SendLog(log); }