private LoggingException BuildLoggingException(string originalMessage, Exception errorLogException) { string errorMessage = 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 += Resources.LoggingExceptionMessage2 + exceptionMessage + 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); }
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(Resources.SandboxLoggingFailed, (Exception)result); throw ex; } } }