public void Log(string type, ToastLogLevel level, string message, IDictionary <string, string> userFields = null) { if (string.IsNullOrEmpty(type)) { type = "NORMAL"; } var uri = ToastUri.Create("logger", new ToastUri.VariableSegment(_appKey), "log"); var methodCall = MethodCall.CreateSyncCall(uri); methodCall.AddParameter("level", level.ToString()) .AddParameter("type", type) .AddParameter("message", message); if (userFields != null) { foreach (var items in userFields) { if (string.IsNullOrEmpty(items.Key)) { ToastLog.Error("20002 : key is null or empty string"); return; } } methodCall.AddParameter("userFields", userFields); } var response = ToastNativeSender.SyncSendMessage(methodCall); ToastLog.Debug("InstanceLogger.Log.Response={0}", response); }
public static void Log(ToastLogLevel logLevel, string message, Dictionary <string, string> userFields = null) { if (!IsInitialized()) { return; } if (userFields != null) { foreach (var items in userFields) { if (string.IsNullOrEmpty(items.Key)) { int errorCode = ToastLoggerErrorCode.InvalidUserKey.Code; string errroMessage = "key is null or empty string"; ToastLog.Error(errorCode + " : " + errroMessage); return; } } } string methodName = MethodBase.GetCurrentMethod().Name; string uri = ToastUri.Create(SERVICE_NAME, methodName.ToLower()); MethodCall methodCall = MethodCall.CreateSyncCall(uri); methodCall.AddParameter("level", logLevel.ToString().ToUpper()); methodCall.AddParameter("message", message); if (userFields != null) { methodCall.AddParameter("userFields", userFields); } Dispatcher.Instance.Post(() => ToastNativeSender.SyncSendMessage(methodCall)); }
public void LoadLogLevelFilter(JSONNode jsonNode) { if (jsonNode[RESULT_KEY][FILTER_KEY][LOG_LEVEL_FILTER_KEY] != null) { if (jsonNode[RESULT_KEY][FILTER_KEY][LOG_LEVEL_FILTER_KEY][ENABLE_KEY] != null) { isLogLevelFilter = jsonNode[RESULT_KEY][FILTER_KEY][LOG_LEVEL_FILTER_KEY][ENABLE_KEY].AsBool; filterLogLevel = (ToastLogLevel)Enum.Parse(typeof(ToastLogLevel), jsonNode[RESULT_KEY][FILTER_KEY][LOG_LEVEL_FILTER_KEY][LOG_LEVEL_KEY]); } } }
public void SetLogObject(string projectKey, string logType, ToastLogLevel logLevel, string logMessage, string transactionId = "") { _data.Add(ToastLoggerFields.PROJECT_KEY, projectKey); _data.Add(ToastLoggerFields.LOG_TYPE, logType); _data.Add(ToastLoggerFields.LOG_SOURCE, ToastLoggerContants.DEFAULT_LOG_SOURCE); _data.Add(ToastLoggerFields.LOG_VERSION, ToastLoggerVersion.VERSION); _data.Add(ToastLoggerFields.LOG_LEVEL, logLevel.ToString()); _data.Add(ToastLoggerFields.LOG_MESSAGE, logMessage); _data.Add(ToastLoggerFields.LOG_CREATE_TIME, ToastUtil.GetEpochMilliSeconds().ToString()); _data.Add(ToastLoggerFields.LOG_TRANSACTION_ID, (transactionId == "") ? Guid.NewGuid().ToString() : transactionId); }
public static void ShowNotification(string body, ToastLogLevel customLogLevel, Corner corner = Corner.BottomRight, double secondsViewable = 3) { var notificationWindow = Application.Current?.Windows?.Cast <Window>() .FirstOrDefault(window => window != null && window.IsActive); // App either hasn't started or doesn't have a main window if (notificationWindow == null) { LogManager.GetCurrentClassLogger().Log(LogLevel.Error, $"Failed to log message: \"{body}\""); return; } #pragma warning disable CA2000 // Dispose objects before losing scope var notifier = new Notifier(configuration => { configuration.PositionProvider = new WindowPositionProvider( parentWindow: notificationWindow, corner: corner, offsetX: 10, offsetY: 10); configuration.LifetimeSupervisor = new TimeAndCountBasedLifetimeSupervisor( notificationLifetime: TimeSpan.FromSeconds(secondsViewable), maximumNotificationCount: MaximumNotificationCount.FromCount(1)); configuration.Dispatcher = Application.Current.Dispatcher; }); #pragma warning restore CA2000 // Dispose objects before losing scope switch (customLogLevel) { case ToastLogLevel.Information: notifier.ShowInformation(body); break; case ToastLogLevel.Success: notifier.ShowSuccess(body); break; case ToastLogLevel.Warning: notifier.ShowWarning(body); break; case ToastLogLevel.Error: notifier.ShowError(body); break; default: throw new ArgumentOutOfRangeException(nameof(customLogLevel), customLogLevel, null); } }
private static void Exception(ToastLogLevel logLevel, string message, string logString, string stackTrace) { var dmpData = EncodeDmpData(logString, stackTrace); var methodName = MethodBase.GetCurrentMethod().Name; var uri = ToastUri.Create(SERVICE_NAME, methodName.ToLower()); var methodCall = MethodCall.CreateSyncCall(uri) .AddParameter("logType", ToastLoggerType.CRASH_FROM_UNITY) .AddParameter("logLevel", logLevel.ToString().ToUpper()) .AddParameter("message", string.IsNullOrEmpty(message) ? "Raises a exception, but message is empty" : message) .AddParameter("dmpData", dmpData) .AddParameter("userFields", new Dictionary <string, string> { { "Unity", Application.unityVersion } }); Dispatcher.Instance.Post(() => ToastNativeSender.SyncSendMessage(methodCall)); }
private static void Report(ToastLogLevel logLevel, string message, string dumpData) { if (!IsInitialized()) { return; } string methodName = "exception"; string uri = ToastUri.Create(SERVICE_NAME, methodName.ToLower()); MethodCall methodCall = MethodCall.CreateSyncCall(uri); methodCall.AddParameter("logType", ToastLoggerType.HANDLED); methodCall.AddParameter("logLevel", logLevel.ToString().ToUpper()); methodCall.AddParameter("message", message); methodCall.AddParameter("dmpData", dumpData); methodCall.AddParameter("userFields", new Dictionary <string, string> { { "Unity", Application.unityVersion } }); Dispatcher.Instance.Post(() => ToastNativeSender.SyncSendMessage(methodCall)); }
public void SetCrashData(string projectKey, string logType, ToastLogLevel logLevel, string logMessage, string transactionId = "") { SetLogObject(projectKey, logType, logLevel, logMessage, transactionId); }
public static void Report(ToastLogLevel logLevel, string message, Exception e) { Report(logLevel, message, ConvertExceptionToString(e)); }
public static void Report(ToastLogLevel logLevel, string message, string logString, string stackTrace) { string dmpData = EncodeDmpData(logString, stackTrace); Report(logLevel, message, dmpData); }