Пример #1
0
        private LoggingException BuildLoggingException(string originalMessage, Exception errorLogException)
        {
            string    errorMessage   = Properties.Resources.LoggingExceptionMessage1;
            Exception innerException = null;

            // Build a dictionary with exception data, that can later be added to the exception
            Dictionary <object, object> exceptionData = new Dictionary <object, object>();

            exceptionData["OriginalMessage"] = originalMessage;

            // If there was an exception with logging to the exception log, add that data here:
            if (errorLogException != null)
            {
                string exceptionMessage = BuildExceptionMessage(errorLogException, null);
                errorMessage += Properties.Resources.LoggingExceptionMessage2 + exceptionMessage + Properties.Resources.LoggingExceptionMessage3 + originalMessage;
                exceptionData["ErrorLogException"] = exceptionMessage;

                // Preferably, use the exception from the error log as the inner exception
                innerException = errorLogException;
            }

            // Now build the exception with the gathered information.
            LoggingException loggingException = new LoggingException(errorMessage, innerException);

            foreach (object key in exceptionData.Keys)
            {
                loggingException.Data.Add(key, exceptionData[key]);
            }

            return(loggingException);
        }
Пример #2
0
        protected virtual void WriteToOperationsLogSandbox(string message, int eventId, SandboxEventSeverity?severity, string category)
        {
            if (SharePointLogger.canAccessSandboxLogging == -1)
            {
                if (SharePointEnvironment.ProxyInstalled(TracingOperationArgs.OperationAssemblyName, TracingOperationArgs.OperationTypeName))
                {
                    SharePointLogger.canAccessSandboxTracing = 1;
                }
                else
                {
                    SharePointLogger.canAccessSandboxTracing = 0;
                }
            }

            if (SharePointLogger.canAccessSandboxTracing == 1)
            {
                var args = new LoggingOperationArgs();
                args.Message  = message;
                args.EventId  = eventId;
                args.Category = category;
                args.Severity = (int?)severity;

                if (SPContext.Current != null)
                {
                    args.SiteID = SPContext.Current.Site.ID;
                }
                else
                {
                    args.SiteID = null;
                }

                var result = SPUtility.ExecuteRegisteredProxyOperation(
                    LoggingOperationArgs.OperationAssemblyName,
                    LoggingOperationArgs.OperationTypeName,
                    args);

                if (result != null && result.GetType().IsSubclassOf(typeof(System.Exception)))
                {
                    var ex = new LoggingException(Properties.Resources.SandboxLoggingFailed, (Exception)result);
                    throw ex;
                }
            }
        }
Пример #3
0
        private LoggingException BuildLoggingException(string originalMessage, Exception errorLogException)
        {
            string errorMessage = Properties.Resources.LoggingExceptionMessage1;
            Exception innerException = null;

            // Build a dictionary with exception data, that can later be added to the exception
            Dictionary<object, object> exceptionData = new Dictionary<object, object>();
            exceptionData["OriginalMessage"] = originalMessage;

            // If there was an exception with logging to the exception log, add that data here:
            if (errorLogException != null)
            {
                string exceptionMessage = BuildExceptionMessage(errorLogException, null);
                errorMessage += Properties.Resources.LoggingExceptionMessage2 + exceptionMessage + Properties.Resources.LoggingExceptionMessage3 + originalMessage;
                exceptionData["ErrorLogException"] = exceptionMessage;

                // Preferably, use the exception from the error log as the inner exception
                innerException = errorLogException;
            } 

            // Now build the exception with the gathered information. 
            LoggingException loggingException = new LoggingException(errorMessage, innerException);
            foreach (object key in exceptionData.Keys)
            {
                loggingException.Data.Add(key, exceptionData[key]);
            }

            return loggingException;
        }
Пример #4
0
        protected virtual void WriteToTraceSandbox(string message, int eventId, SandboxTraceSeverity? severity, string category)
        {
            if (SharePointLogger.canAccessSandboxTracing == -1)
            {
                if (SharePointEnvironment.ProxyInstalled(TracingOperationArgs.OperationAssemblyName, TracingOperationArgs.OperationTypeName))
                {
                    SharePointLogger.canAccessSandboxTracing = 1;
                }
                else
                {
                    SharePointLogger.canAccessSandboxTracing = 0;
                }
            }

            if (SharePointLogger.canAccessSandboxTracing == 1)
            {

                var args = new TracingOperationArgs();
                args.Message = message;
                args.EventId = eventId;
                args.Category = category;
                args.Severity = (int?)severity;
                if (SPContext.Current != null)
                    args.SiteID = SPContext.Current.Site.ID;
                else
                    args.SiteID = null;

                var result = SPUtility.ExecuteRegisteredProxyOperation(
                                        TracingOperationArgs.OperationAssemblyName,
                                         TracingOperationArgs.OperationTypeName,
                                         args);

                if (result != null && result.GetType().IsSubclassOf(typeof(System.Exception)))
                {
                    var ex = new LoggingException(Properties.Resources.SandboxTraceFailed, (Exception)result);
                    throw ex;
                }
            }
        }