public V0100.Objects.ExceptionLog Create(V0100.Objects.ExceptionLog exceptionLog)
        {
            DeviceEntity device = GetDevice();

            ExceptionLogEntity log = new ExceptionLogEntity
            {
                DeviceId             = device.DeviceId,
                RemoteExceptionLogId = exceptionLog.RemoteExceptionLogId,
                Title              = exceptionLog.Title,
                Message            = exceptionLog.Message,
                StackTrace         = exceptionLog.StackTrace,
                LogTime            = exceptionLog.LogTime,
                User               = exceptionLog.User,
                FormName           = exceptionLog.FormName,
                MachineName        = exceptionLog.MachineName,
                MachineOS          = exceptionLog.MachineOS,
                ApplicationVersion = exceptionLog.ApplicationVersion,
                CLRVersion         = exceptionLog.CLRVersion,
                MemoryUsage        = exceptionLog.MemoryUsage,
                ReceivedTime       = DateTime.UtcNow
            };

            log.Save();

            exceptionLog.ExceptionLogId = log.ExceptionLogId;
            exceptionLog.ReceivedTime   = log.ReceivedTime;

            OperationController.Update();

            return(exceptionLog);
        }
        public async Task <ExceptionLogEntity> LogException(Exception exception, string chatId = null, string title = null)
        {
            var json = "";

            if (exception is WebException webException)
            {
                using (var stream = webException.Response.GetResponseStream())
                    using (var reader = new StreamReader(stream ?? throw new InvalidOperationException()))
                    {
                        json = await reader.ReadToEndAsync();
                    }
            }

            var exceptionLog = new ExceptionLogEntity
            {
                ChatId       = chatId,
                Title        = title,
                Exception    = exception.ToString(),
                WebException = json,
            };

            _context.ExceptionLogs.Add(exceptionLog);
            await _context.SaveChangesAsync();

            return(exceptionLog);
        }
 protected override void SendBuffer(LoggingEvent[] events)
 {
     foreach (var evt in events)
     {
         try
         {
             var assembly = String.Join(",", Assembly.GetExecutingAssembly().FullName.Split(',').Take(2));
             var log      = new ExceptionLogEntity
             {
                 DeviceId             = 1,
                 RemoteExceptionLogId = 0,
                 Title   = evt.RenderedMessage.Substring(0, Math.Min(evt.RenderedMessage.Length, ExceptionLogFields.Title.MaxLength)),
                 Message = evt.ExceptionObject != null?evt.ExceptionObject.Message.Substring(0, Math.Min(evt.ExceptionObject.Message.Length, ExceptionLogFields.Message.MaxLength)) : "",
                               StackTrace = evt.ExceptionObject != null?evt.ExceptionObject.StackTrace.Substring(0, Math.Min(evt.ExceptionObject.StackTrace.Length, ExceptionLogFields.StackTrace.MaxLength)) : "",
                                                LogTime            = evt.TimeStamp,
                                                User               = evt.Identity,
                                                FormName           = evt.LoggerName,
                                                MachineName        = Environment.MachineName,
                                                MachineOS          = Environment.OSVersion.VersionString,
                                                ApplicationVersion = assembly,
                                                CLRVersion         = Environment.Version.ToString(),
                                                MemoryUsage        = Environment.WorkingSet.ToString(CultureInfo.InvariantCulture),
                                                ReceivedTime       = DateTime.UtcNow
             };
             log.Save();
         }
         catch
         {
             // eat it
         }
     }
 }
        public V0100.Objects.ExceptionLog Get(string id)
        {
            DeviceEntity device = GetDevice();

            ExceptionLogEntity exceptionLog = GetException(id);

            if (exceptionLog.DeviceId != device.DeviceId)
            {
                throw new WebFaultException <string>("Access to resource denied", HttpStatusCode.Forbidden);
            }

            return(new V0100.Objects.ExceptionLog
            {
                ExceptionLogId = exceptionLog.ExceptionLogId,
                DeviceId = exceptionLog.DeviceId,
                RemoteExceptionLogId = exceptionLog.RemoteExceptionLogId,
                Title = exceptionLog.Title,
                Message = exceptionLog.Message,
                StackTrace = exceptionLog.StackTrace,
                LogTime = exceptionLog.LogTime,
                User = exceptionLog.User,
                FormName = exceptionLog.FormName,
                MachineName = exceptionLog.MachineName,
                MachineOS = exceptionLog.MachineOS,
                ApplicationVersion = exceptionLog.ApplicationVersion,
                CLRVersion = exceptionLog.CLRVersion,
                MemoryUsage = exceptionLog.MemoryUsage,
                ReceivedTime = exceptionLog.ReceivedTime
            });
        }
        public ActionResult View(long exceptionLogId)
        {
            var exception = new ExceptionLogEntity(exceptionLogId);

            if (exception.IsNew)
            {
                throw new HttpException(404, SharedRes.Error.NotFound_Exception);
            }

            return(PartialView(exception));
        }
Example #6
0
        /// <summary>
        /// 异常日志
        /// </summary>
        /// <param name="entity"></param>
        public static void WriteExceptionLog(string method, string message)
        {
            LogDao             logDao = new LogDao();
            ExceptionLogEntity entity = new ExceptionLogEntity()
            {
                ExceptionMessage = message,
                ExceptionModule  = method
            };

            logDao.InsertExceptionLog(entity);
        }
Example #7
0
 /// <summary>
 /// 异常日志
 /// </summary>
 /// <param name="entity"></param>
 /// <returns></returns>
 public int InsertExceptionLog(ExceptionLogEntity entity)
 {
     try
     {
         return(coon.Execute("INSERT INTO ExceptionLog(ExceptionModule,ExceptionMessage) " +
                             "VALUES(@ExceptionModule,@ExceptionMessage)", entity));
     }
     catch (Exception e)
     {
         return(0);
     }
 }
        private static ExceptionLogEntity GetException(string id)
        {
            long exceptionId;

            if (long.TryParse(id, out exceptionId))
            {
                ExceptionLogEntity exceptionLog = new ExceptionLogEntity(exceptionId);
                if (!exceptionLog.IsNew)
                {
                    return(exceptionLog);
                }

                throw new WebFaultException <string>("Item not found", HttpStatusCode.NotFound);
            }

            throw new WebFaultException <string>("Input id must be integer", HttpStatusCode.BadRequest);
        }
Example #9
0
        private ExceptionLogEntity MapToExceptionLogEntity(Exception ex) //AutoMapper
        {
            var res = new ExceptionLogEntity()
            {
                DateCreated = DateTime.UtcNow,
                CreatedBy   = Guid.Empty
            };

            try
            {
                res.LogMethod = ExceptionLogMethod.JsonSerialize;
                res.Exception = JsonConvert.SerializeObject(ex);
            }
            catch (Exception serializeException)
            {
                res.LogMethod      = ExceptionLogMethod.ToString;
                res.SerializeError = JsonConvert.SerializeObject(serializeException);
                res.Exception      = ex.ToString();
            };

            return(res);
        }
Example #10
0
        public static bool SendExceptionImpl(string deviceUniqueKey, Exception ex, ExceptionAdditionalInfo exInfo)
        {
            ExceptionLogEntity ecExceptionLogEntity = new ExceptionLogEntity();

            //ecExceptionLogEntity.CustomerId = customerId;
            ecExceptionLogEntity.DeviceId             = KeyToIdHelpers.ConvertDeviceKey(deviceUniqueKey);
            ecExceptionLogEntity.RemoteExceptionLogId = (long)exInfo.CustomersLogExceptionId;
            //ecExceptionLogEntity.CustomerExceptionObject = ObjectSerialization.ObjectToByteArray(ex);
            ecExceptionLogEntity.Title      = String.Empty;
            ecExceptionLogEntity.Message    = ex.Message;
            ecExceptionLogEntity.StackTrace = ex.StackTrace;
            //ecExceptionLogEntity.CustomerExceptionInnerStackTrace = ex.InnerException.StackTrace;
            ecExceptionLogEntity.LogTime            = exInfo.ExceptionDateTime;
            ecExceptionLogEntity.User               = exInfo.ExceptionUser;
            ecExceptionLogEntity.FormName           = exInfo.ExceptionFormName;
            ecExceptionLogEntity.MachineName        = exInfo.ExceptionMachineName;
            ecExceptionLogEntity.MachineOS          = exInfo.ExceptionMachineOS;
            ecExceptionLogEntity.ApplicationVersion = exInfo.ExceptionApplicationVersion;
            ecExceptionLogEntity.CLRVersion         = exInfo.ExceptionCLRVersion;
            ecExceptionLogEntity.MemoryUsage        = exInfo.ExceptionMemoryUsage;
            ecExceptionLogEntity.ReceivedTime       = DateTime.Now;
            ecExceptionLogEntity.Save();
            return(true);
        }
Example #11
0
        public ActionResult Post()
        {
            // Prepare connection to storage account
            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(AppSettings.ConnectionString);

            try{
                // Unpack the Stripe Event
                var json        = new StreamReader(HttpContext.Request.Body).ReadToEndAsync().Result;
                var stripeEvent = Stripe.EventUtility.ParseEvent(json);

                // Connect to Message Queue
                CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient();
                CloudQueue       queue       = queueClient.GetQueueReference(AppSettings.QueueName);
                queue.CreateIfNotExistsAsync();

                // Connect to LogsTable
                CloudTableClient logsTableClient = storageAccount.CreateCloudTableClient();
                CloudTable       logsTable       = logsTableClient.GetTableReference(AppSettings.StripeEventLogTableName);
                logsTable.CreateIfNotExistsAsync();

                // Ensure idempotency (Has this already been logged?)
                // ToDo: Check LogsTable, Ignore events that have already been processed...

                // We only focus on the events we care about, the remainder are logged for future reference:
                switch (stripeEvent.Type)
                {
                // Handle Stripe events based on type:

                case Stripe.Events.CustomerCreated:
                    // Process CustomerCreated Event...
                    break;

                case Stripe.Events.ChargeSucceeded:
                    // Process ChargeSucceeded Event...
                    break;

                case Stripe.Events.ChargeFailed:
                    // Process ChargeFailed Event...
                    break;

                default:
                    // Process Default Event...
                    break;
                }

                // Send into message queue:
                // Create a message and add it to the queue.
                var queueMessage = new QueueMessage {
                    Id   = stripeEvent.Id,
                    Type = stripeEvent.Type
                };

                var messageAsJson         = JsonConvert.SerializeObject(queueMessage);
                CloudQueueMessage message = new CloudQueueMessage(messageAsJson);
                queue.AddMessageAsync(message);

                // Log processing of this event:
                var eventLogEntity = new EventLogEntity(stripeEvent.Id);
                eventLogEntity.Type = stripeEvent.Type;
                TableOperation insertOperation = TableOperation.Insert(eventLogEntity);
                logsTable.ExecuteAsync(insertOperation);

                // Return status code 200
                return(Ok());
            }
            catch (Exception e)
            {
                // Connect to ExceptionsTable
                CloudTableClient exceptionsTableClient = storageAccount.CreateCloudTableClient();
                CloudTable       exceptionsTable       = exceptionsTableClient.GetTableReference(AppSettings.ExceptionLogTableName);
                exceptionsTable.CreateIfNotExistsAsync();

                // Log the exception:
                var exceptionLogEntity = new ExceptionLogEntity()
                {
                    Message = e.Message
                };
                TableOperation insertOperation = TableOperation.Insert(exceptionLogEntity);
                exceptionsTable.ExecuteAsync(insertOperation);

                // Return status code 400:
                return(BadRequest());
            }
        }