Ejemplo n.º 1
0
        /// <summary>
        /// Call a WCF service to log the given exception.
        /// </summary>
        /// <param name="ex">Exception to log</param>
        /// <returns>Generalized user-friendly error message</returns>
        public static string Log(Exception ex)
        {
            string result = _RM.GetString("DefaultErrorMessage");

            try
            {
                // If the error service is available...
                if (CheckService())
                {
                    // Set targetSite with the method that caught the exception.
                    MethodBase mb         = ex.TargetSite;
                    string     targetSite = null;
                    if (mb != null)
                    {
                        targetSite = mb.ToString();
                    }

                    lock (_LockObject)
                    {
                        // Prepare to use the error logging service.
                        using (LocalErrorServiceClient errorService = new LocalErrorServiceClient())
                        {
                            // Use a memory stream to pass the exception data.
                            using (MemoryStream ms = new MemoryStream())
                            {
                                BinaryFormatter bf = new BinaryFormatter();
                                bf.Serialize(ms, ex);

                                // Log the error and grab the returned generalized error message.
                                result = errorService.Add(DateTime.Now, Assembly.GetExecutingAssembly().GetName().Name,
                                                          targetSite, ms.ToArray());
                            }
                        }
                    }
                }
                return(result);
            }
            catch (Exception)
            {
                return(result);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// See if the error logging service is available.
        /// </summary>
        /// <returns>True if service available.</returns>
        private static bool CheckService()
        {
            bool _ReturnCode = false;

            try
            {
                lock (_LockObject)
                {
                    using (LocalErrorServiceClient errorService = new LocalErrorServiceClient())
                    {
                        _ReturnCode = errorService.ServiceAvail();
                    }
                }
            }
            catch (Exception)
            {
                return(_ReturnCode);
            }
            return(_ReturnCode);
        }