Exemple #1
0
        /// <summary>
        /// Writes a diagnostic message into the trace log, with specified <see cref="TraceSeverity"/>.
        /// </summary>
        /// <param name="message">The message to write into the log.</param>
        /// <param name="eventId">The eventId that corresponds to the event.</param>
        /// <param name="severity">The severity of the exception.</param>
        /// <param name="category">The category to write the message to.</param>
        public void TraceToDeveloper(string message, int eventId, SandboxTraceSeverity severity, string category)
        {
            Validation.ArgumentNotNull(message, "message");


            WriteTraceMessage(message, eventId, severity, category);
        }
Exemple #2
0
        /// <summary>
        /// Writes information about an exception into the log from the sandbox.
        /// </summary>
        /// <param name="exception">The exception to write into the log.</param>
        /// <param name="additionalMessage">Additional information about the exception message.</param>
        /// <param name="eventId">The eventId that corresponds to the event.</param>
        /// <param name="severity">The severity of the exception.</param>
        /// <param name="category">The category to write the message to.</param>
        public void TraceToDeveloper(Exception exception, string additionalMessage, int eventId,
                                     SandboxTraceSeverity severity, string category)
        {
            Validation.ArgumentNotNull(exception, "exception");
            Validation.ArgumentNotNull(additionalMessage, "additionalMessage");

            TraceToDeveloper(BuildExceptionMessage(exception, additionalMessage), eventId, severity, category);
        }
Exemple #3
0
        protected override void WriteToDeveloperTrace(string message, int eventId, SandboxTraceSeverity severity, string category)
        {
            var messageToAdd = new LoggedMessage();

            messageToAdd.Message = message;
            messageToAdd.EventId = eventId;
            messageToAdd.SandboxTraceSeverity = severity;
            messageToAdd.Category             = category;
            Messages.Add(messageToAdd);
        }
            public TestTraceLogger()
            {
                TraceToDeveloperStringInt32SandboxTraceSeverityString = (message, eventId, eventSeverity, category) =>
                {
                    this.Message  = message;
                    this.EventId  = eventId;
                    this.Category = category;
                    this.Severity = eventSeverity;
                };

                TraceToDeveloperStringInt32String = (message, eventId, category) =>
                {
                    this.Message  = message;
                    this.EventId  = eventId;
                    this.Category = category;
                };
            }
Exemple #5
0
 protected override void WriteToDeveloperTrace(string message, int eventId, SandboxTraceSeverity severity, string category)
 {
     try
     {
         if (SharePointEnvironment.InSandbox)
         {
             WriteToTraceSandbox(message, eventId, severity, category);
         }
         else
         {
             WriteToTraceFullTrust(message, eventId, severity, category);
         }
     }
     catch (Exception ex)
     {
         // If the logging failed, throw an error that holds both the original error information and the
         // reason why logging failed. Dont do this if only the tracing failed.
         throw BuildLoggingException(message, ex);
     }
 }
Exemple #6
0
        /// <summary>
        /// Writes a diagnostic message into the trace log, with specified <see cref="TraceSeverity"/>.
        /// </summary>
        /// <param name="message">The message to write into the log.</param>
        /// <param name="eventId">The eventId that corresponds to the event.</param>
        /// <param name="severity">The severity of the exception.</param>
        /// <param name="category">The category to write the message to.</param>
        public void TraceToDeveloper(string message, int eventId, SandboxTraceSeverity severity, string category)
        {
            Validation.ArgumentNotNull(message, "message");


            WriteTraceMessage(message, eventId, severity, category);
        }
Exemple #7
0
        /// <summary>
        /// Writes information about an exception into the log from the sandbox.
        /// </summary>
        /// <param name="exception">The exception to write into the log.</param>
        /// <param name="additionalMessage">Additional information about the exception message.</param>
        /// <param name="eventId">The eventId that corresponds to the event.</param>
        /// <param name="severity">The severity of the exception.</param>
        /// <param name="category">The category to write the message to.</param>
        public void TraceToDeveloper(Exception exception, string additionalMessage, int eventId,
                                              SandboxTraceSeverity severity, string category)
        {
            Validation.ArgumentNotNull(exception, "exception");
            Validation.ArgumentNotNull(additionalMessage, "additionalMessage");

            TraceToDeveloper(BuildExceptionMessage(exception, additionalMessage), eventId, severity, category);
        }
 public void TraceToDeveloper(string message, SandboxTraceSeverity severity)
 {
 }
Exemple #9
0
 private void WriteToTraceFullTrust(string message, int eventId, SandboxTraceSeverity severity, string category)
 {
     TraceLogger.Trace(message, eventId, GetTraceSeverity(severity), category);
 }
 public void TraceToDeveloper(Exception exception, int eventId, SandboxTraceSeverity severity, string category)
 {
 }
 public void TraceToDeveloper(string message, int eventId, SandboxTraceSeverity severity, string category)
 {
 }
 protected override void WriteToDeveloperTrace(string message, int eventId, SandboxTraceSeverity severity, string category)
 {
     throw new NotImplementedException();
 }
Exemple #13
0
 /// <summary>
 /// Translates a <see cref="SandboxTraceSeverity"/> into an TraceSeverity.
 /// SandboxTraceSeverity uses the same enum values.
 /// </summary>
 /// <param name="severity">The severity of the trace</param>
 /// <returns>the equlivalent SharePoint TraceSeverity value</returns>
 public TraceSeverity GetTraceSeverity(SandboxTraceSeverity severity)
 {
     return (TraceSeverity)((int)severity);
 }
Exemple #14
0
 /// <summary>
 /// Write a diagnostic message into the trace log, with default severity for the category.
 /// </summary>
 /// <param name="message">The message to write into the log.</param>
 /// <param name="severity">The severity of the exception.</param>
 public void TraceToDeveloper(string message, SandboxTraceSeverity severity)
 {
     Validation.ArgumentNotNull(message, "message");
     WriteTraceMessage(message, DefaultEventId, severity, null);
 }
Exemple #15
0
 /// <summary>
 /// Writes a sandbox safe developer trace message.
 /// </summary>
 /// <param name="message">The message to trace</param>
 /// <param name="eventId">The event id of the message to trace</param>
 /// <param name="severity">The severity of the message to trace</param>
 /// <param name="category">The category of the message being traced</param>
 protected abstract void WriteToDeveloperTrace(string message, int eventId, SandboxTraceSeverity severity, string category);
Exemple #16
0
 /// <summary>
 /// Writes a sandbox safe developer trace message.
 /// </summary>
 /// <param name="message">The message to trace</param>
 /// <param name="eventId">The event id of the message to trace</param>
 /// <param name="severity">The severity of the message to trace</param>
 /// <param name="category">The category of the message being traced</param>
 protected abstract void WriteToDeveloperTrace(string message, int eventId, SandboxTraceSeverity severity, string category);
Exemple #17
0
 /// <summary>
 /// Override this method to change the way the trace message is created.
 /// </summary>
 /// <param name="message">The message to write into the log.</param>
 /// <param name="eventId">
 /// The eventId that corresponds to the event. This value, coupled with the EventSource is often used by
 /// administrators and IT PRo's to monitor the EventLog of a system.
 /// </param>
 /// <param name="severity">How serious the event is. </param>
 /// <param name="category">The category of the log message.</param>
 /// <returns>The message.</returns>
 protected virtual string BuildSandboxTraceMessage(string message, int eventId, SandboxTraceSeverity severity, string category)
 {
     return(message);
 }
Exemple #18
0
        /// <summary>
        /// Safe method to trace to the sandbox.
        /// </summary>
        /// <param name="message">The message to trace</param>
        /// <param name="eventId">the event id to trace</param>
        /// <param name="severity">the sandbox severity to use</param>
        /// <param name="category">The category to trace under</param>
        private void WriteTraceMessage(string message, int eventId, SandboxTraceSeverity severity, string category)
        {
            string traceMsg = BuildSandboxTraceMessage(message, eventId, severity, category);

            WriteToDeveloperTrace(traceMsg, eventId, severity, category);
        }
Exemple #19
0
 /// <summary>
 /// Safe method to trace to the sandbox.
 /// </summary>
 /// <param name="message">The message to trace</param>
 /// <param name="eventId">the event id to trace</param>
 /// <param name="severity">the sandbox severity to use</param>
 /// <param name="category">The category to trace under</param>
 private void WriteTraceMessage(string message, int eventId, SandboxTraceSeverity severity, string category)
 {
     string traceMsg = BuildSandboxTraceMessage(message, eventId, severity, category);
     WriteToDeveloperTrace(traceMsg, eventId, severity, category);
 }
Exemple #20
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;
                }
            }
        }
Exemple #21
0
 /// <summary>
 /// Override this method to change the way the trace message is created. 
 /// </summary>
 /// <param name="message">The message to write into the log.</param>
 /// <param name="eventId">
 /// The eventId that corresponds to the event. This value, coupled with the EventSource is often used by
 /// administrators and IT PRo's to monitor the EventLog of a system. 
 /// </param>
 /// <param name="severity">How serious the event is. </param>
 /// <param name="category">The category of the log message.</param>
 /// <returns>The message.</returns>
 protected virtual string BuildSandboxTraceMessage(string message, int eventId, SandboxTraceSeverity severity, string category)
 {
     return message;
 }
Exemple #22
0
 protected override void WriteToDeveloperTrace(string message, int eventId, SandboxTraceSeverity severity, string category)
 {
     TraceMessage = message;
 }
Exemple #23
0
 /// <summary>
 /// Write a diagnostic message into the trace log, with default severity for the category.
 /// </summary>
 /// <param name="message">The message to write into the log.</param>
 /// <param name="severity">The severity of the exception.</param>
 public void TraceToDeveloper(string message, SandboxTraceSeverity severity)
 {
     Validation.ArgumentNotNull(message, "message");
     WriteTraceMessage(message, DefaultEventId, severity, null);
 }
Exemple #24
0
 private void WriteToTraceFullTrust(string message, int eventId, SandboxTraceSeverity severity, string category)
 {
     TraceLogger.Trace(message, eventId, GetTraceSeverity(severity), category);
 }
Exemple #25
0
 /// <summary>
 /// Translates a <see cref="SandboxTraceSeverity"/> into an TraceSeverity.
 /// SandboxTraceSeverity uses the same enum values.
 /// </summary>
 /// <param name="severity">The severity of the trace</param>
 /// <returns>the equlivalent SharePoint TraceSeverity value</returns>
 public TraceSeverity GetTraceSeverity(SandboxTraceSeverity severity)
 {
     return((TraceSeverity)((int)severity));
 }
Exemple #26
0
 protected override void WriteToDeveloperTrace(string message, int eventId, SandboxTraceSeverity severity, string category)
 {
     try
     {
         if (SharePointEnvironment.InSandbox)
         {
             WriteToTraceSandbox(message, eventId, severity, category);
         }
         else
         {
             WriteToTraceFullTrust(message, eventId, severity, category);
         }
     }
     catch (Exception ex)
     {
         // If the logging failed, throw an error that holds both the original error information and the 
         // reason why logging failed. Dont do this if only the tracing failed. 
         throw BuildLoggingException(message, ex);
     }
 }