Esempio n. 1
0
        /// <summary>
        /// Saves based upon a mode
        /// </summary>
        public void Save(Model.ExceptionLog.ExceptionLogModel exceptionLogModel)
        {
            // Set some defaults if null
            if (exceptionLogModel.UserCreated == null)
            {
                exceptionLogModel.UserCreated = System.Threading.Thread.CurrentPrincipal.Identity.Name;
            }

            if (exceptionLogModel.UserUpdated == null)
            {
                exceptionLogModel.UserUpdated = System.Threading.Thread.CurrentPrincipal.Identity.Name;
            }

            DateTime now = DateTime.UtcNow;

            if (exceptionLogModel.DateCreated == System.DateTime.MinValue)
            {
                exceptionLogModel.DateCreated = now;
            }

            if (exceptionLogModel.DateUpdated == System.DateTime.MinValue)
            {
                exceptionLogModel.DateUpdated = now;
            }

            try
            {
                this.IExceptionLogRepository.Save(exceptionLogModel);
            }
            catch (Exception innerEx)
            {
                string breakPointMe = innerEx.ToString(); // since we are logging an exception we do not want to recursively call
                System.Diagnostics.EventLog.WriteEntry("Application", "Service.ExceptionLog: Could not write the exception: " + breakPointMe, System.Diagnostics.EventLogEntryType.Error);
            }
        }
Esempio n. 2
0
        public void LogException()
        {
            System.Exception ex = new System.Exception("Unit test exception: " + Guid.NewGuid().ToString());

            Interface.Service.IExceptionLogService exceptionLogService = DI.Container.Resolve <Interface.Service.IExceptionLogService>();

            Guid exceptionLogId = Guid.NewGuid();

            exceptionLogService.Save(ex, exceptionLogId);

            Model.ExceptionLog.ExceptionLogModel exceptionLogModel = exceptionLogService.Get(exceptionLogId);

            Assert.AreEqual(exceptionLogModel.ExceptionMessage, ex.Message);
        }
        /// <summary>
        /// Saves the data to an Azure Table named ExeptionLog
        /// </summary>
        /// <param name="exceptionLogModel"></param>
        public void Save(Model.ExceptionLog.ExceptionLogModel exceptionLogModel)
        {
            ExceptionLogServiceDataServiceContext context = new ExceptionLogServiceDataServiceContext();

            // Copy fields (did not want to include an auto mapper refernce so this is done by hand
            ExceptionLog exceptionLog = new ExceptionLog();

            exceptionLog.ExceptionLogId          = exceptionLogModel.ExceptionLogId;
            exceptionLog.HandlingInstanceId      = exceptionLogModel.HandlingInstanceId;
            exceptionLog.AssemblyName            = exceptionLogModel.AssemblyName;
            exceptionLog.AssemblyVersion         = exceptionLogModel.AssemblyVersion;
            exceptionLog.AssemblyLocation        = exceptionLogModel.AssemblyLocation;
            exceptionLog.MachineName             = exceptionLogModel.MachineName;
            exceptionLog.UserDomainName          = exceptionLogModel.UserDomainName;
            exceptionLog.UserName                = exceptionLogModel.UserName;
            exceptionLog.OSPlatform              = exceptionLogModel.OSPlatform;
            exceptionLog.OSServicePack           = exceptionLogModel.OSServicePack;
            exceptionLog.OSVersion               = exceptionLogModel.OSVersion;
            exceptionLog.is64BitOperatingSystem  = exceptionLogModel.is64BitOperatingSystem;
            exceptionLog.is64BitProcess          = exceptionLogModel.is64BitProcess;
            exceptionLog.ProcessorCount          = exceptionLogModel.ProcessorCount;
            exceptionLog.ExceptionInnerException = exceptionLogModel.ExceptionInnerException;
            exceptionLog.ExceptionMessage        = exceptionLogModel.ExceptionMessage;
            exceptionLog.ExceptionSource         = exceptionLogModel.ExceptionSource;
            exceptionLog.ExceptionStackTrace     = exceptionLogModel.ExceptionStackTrace;
            exceptionLog.UserCreated             = exceptionLogModel.UserCreated;
            exceptionLog.DateCreated             = exceptionLogModel.DateCreated;
            exceptionLog.UserUpdated             = exceptionLogModel.UserUpdated;
            exceptionLog.DateUpdated             = exceptionLogModel.DateUpdated;
            exceptionLog.IsDeleted               = exceptionLogModel.IsDeleted;
            exceptionLog.UserDeleted             = exceptionLogModel.UserDeleted;
            exceptionLog.DateDeleted             = exceptionLogModel.DateDeleted;

            // set some defaults if not provided
            if (exceptionLog.DateCreated == DateTime.MinValue)
            {
                exceptionLog.DateCreated = DateTime.UtcNow;
            }
            if (exceptionLog.DateUpdated == DateTime.MinValue)
            {
                exceptionLog.DateUpdated = DateTime.UtcNow;
            }

            // Make the RowKey = Exception Log Id so we can query faster
            exceptionLog.PartitionKey = exceptionLog.ExceptionLogId.ToString().ToLower();
            exceptionLog.RowKey       = exceptionLog.ExceptionLogId.ToString().ToLower();

            context.InsertOrReplace(exceptionLog);
        } // Save
Esempio n. 4
0
        } // Save

        /// <summary>
        /// Saves an Exception
        /// </summary>
        /// <param name="exception"></param>
        /// <param name="HandlingInstanceId">Used to tie exceptions together</param>
        public void Save(System.Exception exception, Guid exceptionLogId, Guid handlingInstanceId)
        {
            Model.ExceptionLog.ExceptionLogModel exceptionLogModel = new Model.ExceptionLog.ExceptionLogModel();

            DateTime now = DateTime.UtcNow;

            exceptionLogModel.ExceptionLogId     = exceptionLogId;
            exceptionLogModel.HandlingInstanceId = handlingInstanceId;

            // Set Audit Fields
            exceptionLogModel.DateCreated = now;
            exceptionLogModel.UserCreated = System.Threading.Thread.CurrentPrincipal.Identity.Name;

            exceptionLogModel.AssemblyName     = null;
            exceptionLogModel.AssemblyVersion  = null;
            exceptionLogModel.AssemblyLocation = null;

            if (System.Reflection.Assembly.GetEntryAssembly() != null)
            {
                exceptionLogModel.AssemblyName     = System.Reflection.Assembly.GetEntryAssembly().GetName().FullName;
                exceptionLogModel.AssemblyVersion  = System.Reflection.Assembly.GetEntryAssembly().GetName().Version.ToString();
                exceptionLogModel.AssemblyLocation = System.Reflection.Assembly.GetEntryAssembly().Location;
            }

            exceptionLogModel.MachineName    = System.Environment.MachineName;
            exceptionLogModel.UserDomainName = System.Environment.UserDomainName;
            exceptionLogModel.UserName       = System.Environment.UserName;

            exceptionLogModel.OSPlatform    = System.Environment.OSVersion.Platform.ToString();
            exceptionLogModel.OSServicePack = System.Environment.OSVersion.ServicePack;
            exceptionLogModel.OSVersion     = System.Environment.OSVersion.VersionString;

            exceptionLogModel.is64BitOperatingSystem = System.Environment.Is64BitOperatingSystem;
            exceptionLogModel.is64BitProcess         = System.Environment.Is64BitProcess;
            exceptionLogModel.ProcessorCount         = System.Environment.ProcessorCount;

            string exceptionInnerException = null;

            if (exception.InnerException != null)
            {
                exceptionInnerException = exception.InnerException.ToString();
            }
            exceptionLogModel.ExceptionMessage    = exception.Message;
            exceptionLogModel.ExceptionSource     = exception.Source;
            exceptionLogModel.ExceptionStackTrace = exception.StackTrace;

            this.Save(exceptionLogModel);
        } // Save
        } // Save

        /// <summary>
        /// Gets a single item
        /// NOTE: This is every expensive since we are not searching by a parition or row key!!!
        /// </summary>
        /// <param name="exceptionLogId"></param>
        /// <returns></returns>
        public Model.ExceptionLog.ExceptionLogModel Get(Guid exceptionLogId)
        {
            ExceptionLogServiceDataServiceContext context = new ExceptionLogServiceDataServiceContext();
            ExceptionLog exceptionLog = context.Select(exceptionLogId);

            if (exceptionLog == null)
            {
                return(null);
            }
            else
            {
                Model.ExceptionLog.ExceptionLogModel exceptionLogModel = new Model.ExceptionLog.ExceptionLogModel();
                exceptionLogModel.ExceptionLogId          = exceptionLog.ExceptionLogId;
                exceptionLogModel.HandlingInstanceId      = exceptionLog.HandlingInstanceId;
                exceptionLogModel.AssemblyName            = exceptionLog.AssemblyName;
                exceptionLogModel.AssemblyVersion         = exceptionLog.AssemblyVersion;
                exceptionLogModel.AssemblyLocation        = exceptionLog.AssemblyLocation;
                exceptionLogModel.MachineName             = exceptionLog.MachineName;
                exceptionLogModel.UserDomainName          = exceptionLog.UserDomainName;
                exceptionLogModel.UserName                = exceptionLog.UserName;
                exceptionLogModel.OSPlatform              = exceptionLog.OSPlatform;
                exceptionLogModel.OSServicePack           = exceptionLog.OSServicePack;
                exceptionLogModel.OSVersion               = exceptionLog.OSVersion;
                exceptionLogModel.is64BitOperatingSystem  = exceptionLog.is64BitOperatingSystem;
                exceptionLogModel.is64BitProcess          = exceptionLog.is64BitProcess;
                exceptionLogModel.ProcessorCount          = exceptionLog.ProcessorCount;
                exceptionLogModel.ExceptionInnerException = exceptionLog.ExceptionInnerException;
                exceptionLogModel.ExceptionMessage        = exceptionLog.ExceptionMessage;
                exceptionLogModel.ExceptionSource         = exceptionLog.ExceptionSource;
                exceptionLogModel.ExceptionStackTrace     = exceptionLog.ExceptionStackTrace;
                exceptionLogModel.UserCreated             = exceptionLog.UserCreated;
                exceptionLogModel.DateCreated             = exceptionLog.DateCreated;
                exceptionLogModel.UserUpdated             = exceptionLog.UserUpdated;
                exceptionLogModel.DateUpdated             = exceptionLog.DateUpdated;
                exceptionLogModel.IsDeleted               = exceptionLog.IsDeleted;
                exceptionLogModel.UserDeleted             = exceptionLog.UserDeleted;
                exceptionLogModel.DateDeleted             = exceptionLog.DateDeleted;
                return(exceptionLogModel);
            }
        }