Esempio n. 1
0
        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));
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        public void SetUserField(string key, string value)
        {
            var uri        = ToastUri.Create("logger", new ToastUri.VariableSegment(_appKey), "setUserField");
            var methodCall = MethodCall.CreateSyncCall(uri);

            methodCall.AddParameter("key", key)
            .AddParameter("value", value);
            var response = ToastNativeSender.SyncSendMessage(methodCall);

            ToastLog.Debug("InstanceLogger.SetUserField.Response={0}", response);
        }
Esempio n. 4
0
        public InstanceLogger(string appKey, ILoggerSettings settings, ToastServiceZone zone = ToastServiceZone.REAL)
        {
            _appKey = appKey;

            var uri        = ToastUri.Create("logger", new ToastUri.VariableSegment(appKey), "initialize");
            var methodCall = MethodCall.CreateSyncCall(uri);

            methodCall.AddParameter("projectKey", appKey)
            .AddParameter("serviceZone", zone.ToString())
            .AddParameter("setting", settings.SettingName.ToUpper());
            ToastNativeSender.SyncSendMessage(methodCall);
        }
Esempio n. 5
0
        private static void SetCrashLoggerListener()
        {
            var methodName = "SetLoggerListener";
            var uri        = ToastUri.Create(SERVICE_NAME, methodName.ToLower());
            var methodCall = MethodCall.CreateSyncCall(uri)
                             .AddParameter("success", "OnLogSuccess")
                             .AddParameter("filter", "OnLogFilter")
                             .AddParameter("save", "OnLogSave")
                             .AddParameter("error", "OnLogError");

            Dispatcher.Instance.Post(() => ToastNativeSender.SyncSendMessage(methodCall));
        }
Esempio n. 6
0
        public static void SetOptionalPolicies(params string[] properties)
        {
            var propertiesJsonArray = new JSONArray();

            foreach (var property in properties)
            {
                propertiesJsonArray.Add(property);
            }

            var uri        = ToastUri.Create(ServiceName, MethodBase.GetCurrentMethod().Name);
            var methodCall = MethodCall.CreateSyncCall(uri);

            methodCall.AddParameter("properties", propertiesJsonArray);
            ToastNativeSender.SyncSendMessage(methodCall);
        }
Esempio n. 7
0
        public static void Initialize()
        {
            if (_isInitialize)
            {
                ToastLog.Warn("Already initialize " + typeof(ToastSdk).Name);
                return;
            }

            var methodName = MethodBase.GetCurrentMethod().Name;
            var uri        = ToastUri.Create(ServiceName, methodName.ToLower());
            var methodCall = MethodCall.CreateSyncCall(uri);
            var response   = ToastNativeSender.SyncSendMessage(methodCall);

            if (response != null)
            {
                _isInitialize = response.Result.IsSuccessful;
            }
        }
        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));
        }
Esempio n. 9
0
        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));
        }
Esempio n. 10
0
        public static void Initialize(ToastLoggerConfiguration loggerConfiguration)
        {
            if (string.IsNullOrEmpty(loggerConfiguration.AppKey))
            {
                int    errorCode    = ToastLoggerErrorCode.InvalidUserKey.Code;
                string errroMessage = "AppKey is null or empty string";
                ToastLog.Error(errorCode + " : " + errroMessage);
                return;
            }

            if (_isInitialized)
            {
                ToastLog.Warn("ToastLogger has already been initialized.");
                return;
            }

            string     methodName = MethodBase.GetCurrentMethod().Name;
            string     uri        = ToastUri.Create(SERVICE_NAME, methodName.ToLower());
            MethodCall methodCall = MethodCall.CreateSyncCall(uri);

            methodCall.AddParameter("projectKey", loggerConfiguration.AppKey);
            methodCall.AddParameter("serviceZone", loggerConfiguration.ServiceZone.ToString().ToUpper());
            methodCall.AddParameter("enableCrashReporter", loggerConfiguration.EnableCrashReporter);
            var result = ToastNativeSender.SyncSendMessage(methodCall);

            if (result == null || !result.Result.IsSuccessful)
            {
                return;
            }
            ToastCrashManager.Instance.Initialize(
                loggerConfiguration.EnableCrashReporter,
                loggerConfiguration.EnableCrashErrorLog);

            _isInitialized = true;

            ToastAuditLog.SendUsageLog();
        }
Esempio n. 11
0
        public static void SetUserField(string key, string value)
        {
            if (!IsInitialized())
            {
                return;
            }

            if ((key == null) || (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("key", key);
            methodCall.AddParameter("value", value);

            Dispatcher.Instance.Post(() => ToastNativeSender.SyncSendMessage(methodCall));
        }