Provides methods to log exceptions in Azure table storage.
Пример #1
0
        /// <summary>
        /// Logs error message in Azure table storage or Event Viewer.
        /// </summary>
        /// <param name="exception">Exception object</param>
        /// <param name="className">Class Name where exception occur</param>
        /// <param name="methodName">Name of the method.</param>
        /// <param name="logTableName">Name of the log table.</param>
        /// <param name="lineNumber">Line Number of the log table.</param>
        /// <returns>Error logged in event viewer</returns>
        public ErrorResponse MatterCenterExceptions(Exception exception, string className, string methodName, string logTableName, int lineNumber)
        {
            string errorDate = DateTime.Now.ToString(logTables.AzureRowKeyDateFormat, CultureInfo.InvariantCulture);
            string errorCode = string.Empty;
            string result    = string.Empty;

            try
            {
                if (null != exception)
                {
                    if (Convert.ToBoolean(logTables.IsLoggingOnAzure, CultureInfo.InvariantCulture))
                    {
                        //// Log to Azure table storage
                        errorDate = AzureLogger.LogInAzure(exception, className, methodName, logTableName, lineNumber, logTables, generalSettings);
                    }
                    else
                    {
                        errorResponse = new ErrorResponse()
                        {
                            Message    = exception.Message,
                            ClassName  = className,
                            MethodName = methodName,
                            LineNumber = lineNumber
                        };
                        //// Log to event viewer
                        EventViewerLogger.LogInEventViewer(errorResponse.ToString(), ServiceConstants.EVENT_ERROR, logTables);
                    }
                    errorResponse = new ErrorResponse()
                    {
                        ErrorCode = exception.HResult.ToString(),
                        ErrorDate = errorDate,
                        Message   = ServiceUtility.RemoveEscapeCharacter(exception.Message),
                    };
                }
                else
                {
                    errorResponse = new ErrorResponse()
                    {
                        ErrorCode   = ServiceConstants.LOGGING_FAILED_CODE.ToString(),
                        ErrorDate   = errorDate,
                        Message     = ServiceUtility.RemoveEscapeCharacter(exception.Message),
                        Description = ServiceConstants.LOGGING_FAILED_MESSAGE
                    };
                }
            }
            catch (Exception)
            {
                errorResponse = new ErrorResponse()
                {
                    ErrorCode   = ServiceConstants.LOGGING_FAILED_CODE.ToString(),
                    ErrorDate   = errorDate,
                    Message     = ServiceUtility.RemoveEscapeCharacter(exception.Message),
                    Description = ServiceConstants.LOGGING_FAILED_MESSAGE
                };
            }
            return(errorResponse);
        }
Пример #2
0
        /// <summary>
        /// Logs error message in Azure table storage or Event Viewer.
        /// </summary>
        /// <param name="exception">Exception object</param>
        /// <param name="className">Class Name where exception occur</param>
        /// <param name="methodName">Name of the method.</param>
        /// <param name="logTableName">Name of the log table.</param>
        /// <param name="lineNumber">Line Number of the log table.</param>
        /// <returns>Error logged in event viewer</returns>
        public static string MatterCenterExceptions(Exception exception, string className, string methodName, string logTableName, int lineNumber)
        {
            string errorDate = DateTime.Now.ToString(ConstantStrings.AzureRowKeyDateFormat, CultureInfo.InvariantCulture);
            string errorCode = string.Empty;
            string result    = string.Empty;

            try
            {
                if (null != exception)
                {
                    if (Convert.ToBoolean(ConstantStrings.IsLoggingOnAzure, CultureInfo.InvariantCulture))
                    {
                        //// Log to Azure table storage
                        errorDate = AzureLogger.LogInAzure(exception, className, methodName, logTableName, lineNumber);
                    }
                    else
                    {
                        string logMessage = string.Concat(ConstantStrings.ExceptionMessage + exception.Message + " " + ConstantStrings.ClassName + className + " " + ConstantStrings.MethodName + methodName + " " + ConstantStrings.LineNumber + lineNumber);
                        //// Log to event viewer
                        EventViewerLogger.LogInEventViewer(logMessage, ConstantStrings.EventError);
                    }
                    errorCode = string.Format(CultureInfo.InvariantCulture, ConstantStrings.ErrorCode, exception.HResult, errorDate);
                    result    = string.Format(CultureInfo.InvariantCulture, ConstantStrings.ServiceResponse, errorCode, ServiceUtility.RemoveEscapeCharacter(exception.Message));
                }
                else
                {
                    errorCode = string.Format(CultureInfo.InvariantCulture, ConstantStrings.ErrorCode, ConstantStrings.LoggingFailedCode, errorDate);
                    result    = string.Format(CultureInfo.InvariantCulture, ConstantStrings.ServiceResponse, errorCode, ConstantStrings.LoggingFailedMessage);
                }
            }
            catch (Exception)
            {
                errorCode = string.Format(CultureInfo.InvariantCulture, ConstantStrings.ErrorCode, ConstantStrings.LoggingFailedCode, errorDate);
                result    = string.Format(CultureInfo.InvariantCulture, ConstantStrings.ServiceResponse, errorCode, ConstantStrings.LoggingFailedMessage);
            }
            return(result);
        }