public override string Log(Error error)
        {
            Guid Id = Guid.NewGuid();

            // if exception is of type BusinessException, use the Correlation ID as the row key for the log entry
            if (error.Exception != null && error.Exception.GetType().IsAssignableFrom(typeof(BusinessException)))
            {
                Id = ((BusinessException)error.Exception).CorrelationID;
            }

            AzureLogEntry entity = new AzureLogEntry(error.Time, Id)
            {
                Host     = error.HostName,
                Type     = error.Type,
                ErrorXml = ErrorXml.EncodeString(error),
                Message  = error.Message,
                Code     = error.StatusCode,
                User     = error.User,
                Source   = error.Source,
                Logger   = "Elmah"
            };

            _ctx.AddObject(storageTableName, entity);
            _ctx.SaveChanges();

            return(entity.ID.ToString());
        }
        protected override void Append(LoggingEvent loggingEvent)
        {
            try
            {
                Guid Id = Guid.NewGuid();

                // if exception is of type BusinessException, use the Correlation ID as the row key for the log entry
                if (loggingEvent.ExceptionObject != null && loggingEvent.ExceptionObject.GetType().IsAssignableFrom(typeof(BusinessException)))
                {
                    Id = ((BusinessException)loggingEvent.ExceptionObject).CorrelationID;
                }

                AzureLogEntry logEntry = new AzureLogEntry(DateTime.Now, Id)
                {
                    Logger    = loggingEvent.LoggerName,
                    Timestamp = loggingEvent.TimeStamp,
                    Message   = loggingEvent.RenderedMessage,
                    Level     = loggingEvent.Level.Name,
                    Source    = loggingEvent.LocationInformation.FullInfo,
                    User      = loggingEvent.UserName
                };

                Exception exception = loggingEvent.ExceptionObject as LogException ?? new LogException(loggingEvent.RenderedMessage);
                logEntry.ErrorXml = ErrorXml.EncodeString(new Error(exception));

                _ctx.Log(logEntry);
            }
            catch (Exception e)
            {
                ErrorHandler.Error(string.Format("{0}: Could not write log entry to {1}: {2}",
                                                 GetType().AssemblyQualifiedName, storageTableName, e.Message));
            }
        }
        public override ErrorLogEntry GetError(string id)
        {
            var query = from entity in _ctx.CreateQuery <AzureLogEntry>(storageTableName)
                        where AzureLogEntry.GetRowKey(Guid.Parse(id)) == entity.RowKey
                        select entity;

            AzureLogEntry errorEntity = query.FirstOrDefault();

            if (errorEntity == null)
            {
                return(null);
            }

            return(new ErrorLogEntry(this, id, GetElmahError(errorEntity.ErrorXml)));
        }