public void AddLogItem(LogItem item, LogItemBlobRequest blob = null)
 {
     if (blob != null)
     {
         mCoData.Add(item, blob);
     }
     mItems.Add(item);
 }
        private void Register(Device dev)
        {
            dev.App = _appName;
            dev.Owner = _owner;
            dev.AppVersion = ApplicationInfo.Version;
            if (_deviceID == null || _deviceID == 0 || _resend)
            {
                dev = SendDeviceToServer(dev);
                if(dev != null)
                {
                    _deviceID = dev.DeviceID;
                    RLSettings.DeviceID = _deviceID;
                }
            }

            if (_self._deviceID == 0)
            {
                // only if request to server was sucesfull, but respond doesn't have
                // an ID
                _self._connector = null;
                throw new InvalidOperationException("Unable to register device!");
            }

            _logSender = new LogSender(_connector);

            //push
            if (_pushNotifications)
            {
                try
                {
                    OnRegisterPushNotifications(String.IsNullOrEmpty(dev.PushID));
                }
                catch (Exception e)
                {
                    RLog.E(this, e);
                }
            }

            //settings
            try
            {
                Respond<Settings[]> settings = LoadSetttingsBlocking();
                OnLoadSettings(settings);
                if (SettingsLoaded != null)
                {
                    SettingsLoaded.Invoke(this, settings);
                }
            }
            catch (Exception e)
            {
                //ignore error for load settings
                RLog.E(this, e);
            }

            //unhandled exception in main thread
            string stack = RLSettings.UnhandledExceptionStack;
            if (!String.IsNullOrEmpty(stack))
            {
                LogItem li = CreateLogItem();
                li.Message = "Unhandled exception history";
                LogItemBlobRequest libr = new LogItemBlobRequest(LogItemBlobRequest.MIME_TEXT_PLAIN, "fatalerror.txt", stack);
                libr.IsUnhandledException = true;
                RLog.Send(typeof(Application), "UnhandledException", "History stack trace", libr);
            }

            if (RegistrationFinished != null)
            {
                RegistrationFinished.Invoke(this, EventArgs.Empty);
            }
        }
Beispiel #3
0
        /// <summary>
        /// Generic implementation of sending
        /// </summary>
        /// <param name="source">Any kind of object used like source on web client</param>
        /// <param name="category">Base category for better filtering</param>
        /// <param name="msg"></param>
        /// <param name="libr">Optional blob as attachment</param>
        public static void Send(object source, string category, string msg, LogItemBlobRequest libr = null)
        {
            if (sMode == TURN_OFF)
            {
                return;
            }
            LogItem li = RemoteLog.CreateLogItem();
            if (li == null)
            {// not yet initialized
                return;
            }
            li.Category = category;
            li.Message = msg;
            if (source != null)
            {
                string n = source.GetType().Name;
                if (String.IsNullOrEmpty(n))
                {
                    n = "AnonymousClass";
                }
                li.Source = n;
            }

            LogSender ls = RemoteLog.LogSender;
            if (ls != null)
            {
                ls.AddLogItem(li, libr);
            }
        }
        /// <summary>
        /// Call it for register unhandled exception handler
        /// </summary>
        public static void RegisterUnhandledExceptionHandler()
        {
            Application.Current.UnhandledException += new EventHandler<ApplicationUnhandledExceptionEventArgs>((object o, ApplicationUnhandledExceptionEventArgs ea)
                =>
                {
                    if ((RLog.Mode & RLog.ERROR) == RLog.ERROR)
                    {
                        Exception ex = ea.ExceptionObject;

                        if (ex is UnhandledExceptionKillApp)
                        {
                            return;
                        }
                        else
                        {
                            ea.Handled = true;
                        }

                        //must be in another thread, otherwise sender thread is block for infinite
                        Thread t = new Thread(new ThreadStart(() =>
                        {
                            try
                            {
                                LogItem li = RemoteLog.CreateLogItem();

                                string msg = String.Format("V:{0} Date:{1}\n{2}\n{3}\n\n",
                                    ApplicationInfo.Version,
                                    DateTime.Now.ToString(FORMAT),
                                    ex.Message,
                                    GetStackTrace(ea.ExceptionObject));

                                LogItemBlobRequest libr = new LogItemBlobRequest(LogItemBlobRequest.MIME_TEXT_PLAIN,
                                                                                  "fatalerror.txt",
                                                                                  msg);
                                libr.IsUnhandledException = true;
                                bool isKillApp = ex is KillAppException;

                                //save stack for case a problem during sending
                                if (!isKillApp)
                                {
                                    String oldStack = RLSettings.UnhandledExceptionStack;
                                    oldStack = msg + "\n\n" + oldStack;
                                    RLSettings.UnhandledExceptionStack = oldStack;
                                }

                                RLog.Send(typeof(RemoteLog), isKillApp ? "KillApp" : "UnhandledException", ex.Message, libr);
                                _logSender.WaitForEmptyQueue();
                            }
                            catch (Exception)
                            {
                                /* just ignore it now */
                                // save it for late send
                            }

                            //throw new exception for kill app
                            throw new UnhandledExceptionKillApp();
                        }));
                        t.Name = "UnhandledExceptionSendingThread";
                        t.Start();
                    }
                });
        }
 public Respond<Object> SendItem(LogItemBlobRequest item)
 {
     string json = JsonConvert.SerializeObject(item, RemoteLog.Settings);
     string url = String.Format("{0}?{1}",URL + LOGS_URL, HttpUtility.UrlEncode(json));
     string response = SendRequest(item.Data, url , HTTP_PUT);
     Respond<Object> r = JsonConvert.DeserializeObject<Respond<Object>>(response, RemoteLog.Settings);
     return r;
 }