Tuesday, October 21, 2014

Logging error in event viewer

        void LogError(TraceSeverity Level, Exception exception)
        {
            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                string errorMessage = exception.Message + "--" + exception.StackTrace;
                SPDiagnosticsService.Local.WriteTrace(0,
                    new SPDiagnosticsCategory("Error Log", Level, EventSeverity.Error), TraceSeverity.Unexpected, errorMessage, null);
            });
        }

No comments:

Post a Comment