public void LogError(string ErrorMessage, string type) { SPSecurity.RunWithElevatedPrivileges(delegate() { if (!EventLog.SourceExists("Pierce Mongo Migration Job")) { EventLog.CreateEventSource("Pierce Mongo Migration Job", "Pierce Mongo Migration Job"); } if (type == "error") { EventLog.WriteEntry("Pierce Mongo Migration Job", ErrorMessage, EventLogEntryType.Information); } if (type == "error") { EventLog.WriteEntry("Pierce Mongo Migration Job", ErrorMessage, EventLogEntryType.Error); } SPDiagnosticsService diagSvc = SPDiagnosticsService.Local; diagSvc.WriteTrace(0, new SPDiagnosticsCategory("Pierce Mongo Migration Job", TraceSeverity.Monitorable, EventSeverity.Error), TraceSeverity.Monitorable, "An exception occurred: {0}", new object[] { ErrorMessage }); }); }
/// <summary> /// A site was provisioned. /// </summary> public override void WebProvisioned(SPWebEventProperties properties) { SPDiagnosticsService diagSvc = SPDiagnosticsService.Local; SPSecurity.RunWithElevatedPrivileges(delegate() { try { base.WebProvisioned(properties); var rootWeb = properties.Web.Site.RootWeb; var currentWeb = properties.Web; var siteCollection = currentWeb.Site; using (currentWeb) { var webAppRelativePath = BrandingHelper.WebAppPath(currentWeb, siteCollection); BrandingHelper.InheritTopSiteBranding(currentWeb, rootWeb, siteCollection, webAppRelativePath); } } catch (Exception ex) { diagSvc.WriteTrace(0, new SPDiagnosticsCategory("Error Info", TraceSeverity.Monitorable, EventSeverity.Error), TraceSeverity.Monitorable, "Houston, we have a problem in WebProvisioned event: {0}---{1}", ex.InnerException, ex.StackTrace); } }); }
/// <summary> /// Adding ribbon tab to control's page here /// </summary> protected override void OnPreRender(EventArgs e) { base.OnPreRender(e); if (!DisplayTab) { return; } var tabDefinition = GetTabDefinition(); try { if (SPRibbon.GetCurrent(this.Page) == null) { return; } if (tabDefinition != null && !this.DesignMode) { RibbonController.Current.AddRibbonTabToPage(tabDefinition, this.Page, false); } } catch (Exception ex) { SPDiagnosticsService diagSvc = SPDiagnosticsService.Local; diagSvc.WriteTrace(0, new SPDiagnosticsCategory("Fluent Ribbon", TraceSeverity.Monitorable, EventSeverity.Error), TraceSeverity.Monitorable, "Error occured: " + ex.Message + "\nStackTrace: " + ex.StackTrace); } }
public static void WriteLog(string strLogMsg) { // Nik20131028 - Commented out to help clean the logs, and prevent infrastructure from thinking that this slows down the server... SPDiagnosticsService diagSvc = SPDiagnosticsService.Local; LogEngine.Log(new Exception(strLogMsg), "WET Theme"); diagSvc.WriteTrace(0, new SPDiagnosticsCategory("WET Theme", TraceSeverity.Unexpected, EventSeverity.Error), TraceSeverity.Unexpected, "WET Theme for SharePoint 2010: {0}", new object[] { strLogMsg }); }
void context_PostAuthenticateRequest(object sender, EventArgs e) { //Look for claims. try { //Get the application and context sources. HttpApplication application = (HttpApplication)sender; HttpContext context = application.Context; //Look for the claims identity. IClaimsPrincipal cp = context.User as IClaimsPrincipal; if (cp != null) { StringBuilder claimsInfo = new StringBuilder(2048); //Get the claims identity so we can enumerate claims. IClaimsIdentity ci = (IClaimsIdentity)cp.Identity; //See if there are claims present before running through this. if (ci.Claims.Count > 0) { //start the string build claimsInfo.Append("The following claims were found in this request for " + cp.Identity.Name + ": " + Environment.NewLine); //Enumerate all claims. foreach (Claim c in ci.Claims) { Debug.WriteLine(c.ClaimType + " = " + c.Value); claimsInfo.Append(c.ClaimType + " = " + c.Value + Environment.NewLine); } //write out the claim infomation to the ULS log. try { SPDiagnosticsCategory category = new SPDiagnosticsCategory("SharePoint Claims Enumeration", TraceSeverity.Medium, EventSeverity.Information); SPDiagnosticsService ds = SPDiagnosticsService.Local; ds.WriteEvent(1963, category, EventSeverity.Information, claimsInfo.ToString()); } catch { //Ignore. } } } } catch (Exception ex) { //Ignore. Debug.WriteLine(ex.Message); } }
public static void LogEvent(string subject, string body) { SPDiagnosticsService diagSvc = SPDiagnosticsService.Local; diagSvc.WriteTrace(0, new SPDiagnosticsCategory("STAFix category", TraceSeverity.Monitorable, EventSeverity.Information), TraceSeverity.Monitorable, subject.ToString() + "{0}", new object[] { body.ToString() }); }
private static void LogToULS(Exception exp) { SPDiagnosticsService diagSvc = SPDiagnosticsService.Local; diagSvc.WriteTrace(0, new SPDiagnosticsCategory(loggingSource, TraceSeverity.Unexpected, EventSeverity.Error), TraceSeverity.Unexpected, exp.ToString() ); }
public static void Log(string message) { SPDiagnosticsService diagSvc = SPDiagnosticsService.Local; diagSvc.WriteTrace(0, new SPDiagnosticsCategory("My Category", TraceSeverity.Monitorable, EventSeverity.Error), TraceSeverity.Monitorable, message); }
public static void LogToULS(string message, TraceSeverity traceSeverity, EventSeverity eventSeverity) { try { SPDiagnosticsCategory category = new SPDiagnosticsCategory("Zimbra Settings", traceSeverity, eventSeverity); SPDiagnosticsService ds = SPDiagnosticsService.Local; ds.WriteTrace(0, category, traceSeverity, message); } catch { } }
public static void LogExceptionToSPLog(string webpartname, string methodname, Exception ex) { string _errorTitle = "WebPart Name :" + webpartname + " - Method Name :" + methodname; SPDiagnosticsService diagSvc = SPDiagnosticsService.Local; diagSvc.WriteTrace(0, new SPDiagnosticsCategory(_errorTitle, TraceSeverity.Monitorable, EventSeverity.Error), TraceSeverity.Monitorable, "An exception occurred: {0}", new object[] { ex }); }
public static void LogError(string subject, string body, Exception ex = null) { SPDiagnosticsService diagSvc = SPDiagnosticsService.Local; diagSvc.WriteTrace(0, new SPDiagnosticsCategory("STAFix category", TraceSeverity.Unexpected, EventSeverity.Error), TraceSeverity.Monitorable, subject.ToString() + "{0}", new object[] { body.ToString() }); if (ex != null) { ElasticEmail.EmailGenerator.ReportError(ex, ex.TargetSite.ToString()); } }
private void page_PreRenderComplete(object sender, EventArgs e) { try { Page page = sender as Page; if (RibbonCommandRepository.Current.GetCommandsCount() > 0) { RegisterCommands(page); } } catch (Exception ex) { SPDiagnosticsService diagSvc = SPDiagnosticsService.Local; diagSvc.WriteTrace(0, new SPDiagnosticsCategory("Ribbon", TraceSeverity.Monitorable, EventSeverity.Error), TraceSeverity.Monitorable, "Error occured: " + ex.Message + "\nStackTrace: " + ex.StackTrace); } }
/// <summary> /// SelectData Method creates a DataTable from the data fetched from SharePoint List or Doc Library and returns the DataTable /// </summary> /// <returns></returns> public DataTable SelectData() { DataTable dataSource = new DataTable(); try { SPSite site = SPContext.Current.Web.Site; SPWeb web = site.OpenWeb(); SPList lstICSSDocuments = web.Lists["PhotoList"]; //create document library or List and add column year,Description,Url,Name, Title is inbuilt. SPQuery query = new SPQuery(); IEnumerable <SPListItem> lstItemICSSDocuments = lstICSSDocuments.GetItems(query).OfType <SPListItem>(); dataSource.Columns.Add("Year"); dataSource.Columns.Add("Description"); dataSource.Columns.Add("Name"); dataSource.Columns.Add("Title"); dataSource.Columns.Add("Url"); SPSecurity.RunWithElevatedPrivileges(delegate() { //SPGroup grpName = web.Groups["ICSSViewers"]; var committeeAndGroupDocumentswithURL = lstItemICSSDocuments.Select(x => new { Year = x["Year"], Description = x["Description"], Name = x["Name"], Title = x["Title"], Url = site.Url + "/" + x.Url }); foreach (var document in committeeAndGroupDocumentswithURL) { DataRow dr = dataSource.NewRow(); dr["Title"] = document.Title; dr["Url"] = document.Url; dr["Name"] = document.Name; dr["Description"] = document.Description; dr["Year"] = document.Year; dataSource.Rows.Add(dr); } }); web.Dispose(); } catch (Exception ex) { SPDiagnosticsService diagnosticsService = SPDiagnosticsService.Local; SPDiagnosticsCategory cat = diagnosticsService.Areas["SharePoint Foundation"].Categories["Unknown"]; diagnosticsService.WriteTrace(1, cat, TraceSeverity.Medium, ex.StackTrace, cat.Name, cat.Area.Name); SPUtility.TransferToErrorPage("Some Error occured, Please try after some time. <br/> If problem persists, contact your adminstrator"); } return(dataSource); }
/// <summary> /// Initializes a new instance of the <see cref="TraceLog"/> class. /// </summary> public TraceLog() { SPDiagnosticsService diagnosticsService = SPDiagnosticsService.Local; SPParamCollection parameters = new SPParamCollection(); parameters.Add(new SPParam("logdirectory", "log", false, diagnosticsService.LogLocation, new SPNonEmptyValidator())); parameters.Add(new SPParam("logfilecount", "num", false, diagnosticsService.DaysToKeepLogs.ToString(), new SPIntRangeValidator(0, 1024))); parameters.Add(new SPParam("logfileminutes", "min", false, diagnosticsService.LogCutInterval.ToString(), new SPIntRangeValidator(0, 1440))); parameters.Add(new SPParam("allowlegacytraceproviders", "legacytracers", false, diagnosticsService.AllowLegacyTraceProviders.ToString(), new SPTrueFalseValidator())); parameters.Add(new SPParam("customerexperienceimprovementprogramenabled", "ceipenabled", false, diagnosticsService.CEIPEnabled.ToString(), new SPTrueFalseValidator())); parameters.Add(new SPParam("errorreportingenabled", "errreportenabled", false, diagnosticsService.ErrorReportingEnabled.ToString(), new SPTrueFalseValidator())); parameters.Add(new SPParam("errorreportingautomaticuploadenabled", "errreportautoupload", false, diagnosticsService.ErrorReportingAutomaticUpload.ToString(), new SPTrueFalseValidator())); parameters.Add(new SPParam("downloaderrorreportingupdatesenabled", "errreportupdates", false, diagnosticsService.DownloadErrorReportingUpdates.ToString(), new SPTrueFalseValidator())); parameters.Add(new SPParam("logmaxdiskspaceusageenabled", "maxdiskspaceusage", false, diagnosticsService.LogMaxDiskSpaceUsageEnabled.ToString(), new SPTrueFalseValidator())); parameters.Add(new SPParam("eventlogfloodprotectionenabled", "floodprotection", false, diagnosticsService.EventLogFloodProtectionEnabled.ToString(), new SPTrueFalseValidator())); parameters.Add(new SPParam("scripterrorreportingenabled", "scripterrorreporting", false, diagnosticsService.ScriptErrorReportingEnabled.ToString(), new SPTrueFalseValidator())); parameters.Add(new SPParam("scripterrorreportingrequireauth", "scripterrorreqauth", false, diagnosticsService.ScriptErrorReportingRequireAuth.ToString(), new SPTrueFalseValidator())); parameters.Add(new SPParam("eventlogfloodprotectionthreshold", "floodprotectionthreshold", false, diagnosticsService.EventLogFloodProtectionThreshold.ToString(), new SPIntRangeValidator(0, 100))); parameters.Add(new SPParam("eventlogfloodprotectiontriggerperiod", "floodprotectiontrigger", false, diagnosticsService.EventLogFloodProtectionTriggerPeriod.ToString(), new SPIntRangeValidator(1, 1440))); parameters.Add(new SPParam("scripterrorreportingdelay", "scriptreportingdelay", false, diagnosticsService.ScriptErrorReportingDelay.ToString(), new SPIntRangeValidator(1, 1440))); StringBuilder sb = new StringBuilder(); sb.Append("\r\n\r\nSets the log file location (note that the location must exist on each server) and the maximum number of log files to maintain and how long to capture events to a single file.\r\n\r\nParameters:"); sb.Append("\r\n\t[-logdirectory <log file location>]"); sb.Append("\r\n\t[-logfilecount <number of log files to create (0-1024)>]"); sb.Append("\r\n\t[-logfileminutes <number of minutes to use a log file (0-1440)>]"); sb.Append("\r\n\t[-allowlegacytraceproviders <true|false>]"); sb.Append("\r\n\t[-customerexperienceimprovementprogramenabled <true|false>]"); sb.Append("\r\n\t[-errorreportingenabled <true|false>]"); sb.Append("\r\n\t[-errorreportingautomaticuploadenabled <true|false>]"); sb.Append("\r\n\t[-downloaderrorreportingupdatesenabled <true|false>]"); sb.Append("\r\n\t[-logmaxdiskspaceusageenabled <true|false>]"); sb.Append("\r\n\t[-eventlogfloodprotectionenabled <true|false>]"); sb.Append("\r\n\t[-scripterrorreportingenabled <true|false>]"); sb.Append("\r\n\t[-scripterrorreportingrequireauth <true|false>]"); sb.Append("\r\n\t[-eventlogfloodprotectionthreshold <number between 0 and 100>]"); sb.Append("\r\n\t[-eventlogfloodprotectiontriggerperiod <number between 1 and 1440>]"); sb.Append("\r\n\t[-scripterrorreportingdelay <number between 1 and 1440>]"); Init(parameters, sb.ToString()); }
/// <summary> /// Runs the specified command. /// </summary> /// <param name="command">The command.</param> /// <param name="keyValues">The key values.</param> /// <param name="output">The output.</param> /// <returns></returns> public override int Execute(string command, StringDictionary keyValues, out string output) { output = string.Empty; string logDirectory = Params["logdirectory"].Value; int logFileCount = int.Parse(Params["logfilecount"].Value); int logFileMinutes = int.Parse(Params["logfileminutes"].Value); bool allowLegacyTraceProviders = bool.Parse(Params["allowlegacytraceproviders"].Value); bool customerExperienceImprovementProgramEnabled = bool.Parse(Params["customerexperienceimprovementprogramenabled"].Value); bool errorReportingEnabled = bool.Parse(Params["errorreportingenabled"].Value); bool errorReportingAutomaticUploadEnabled = bool.Parse(Params["errorreportingautomaticuploadenabled"].Value); bool downloadErrorReportingUpdatesEnabled = bool.Parse(Params["downloaderrorreportingupdatesenabled"].Value); bool logMaxDiskSpaceUsageEnabled = bool.Parse(Params["logmaxdiskspaceusageenabled"].Value); bool eventLogFloodProtectionEnabled = bool.Parse(Params["eventlogfloodprotectionenabled"].Value); bool scriptErrorReportingEnabled = bool.Parse(Params["scripterrorreportingenabled"].Value); bool scriptErrorReportingRequireAuth = bool.Parse(Params["scripterrorreportingrequireauth"].Value); int eventLogFloodProtectionThreshold = int.Parse(Params["eventlogfloodprotectionthreshold"].Value); int eventLogFloodProtectionTriggerPeriod = int.Parse(Params["eventlogfloodprotectiontriggerperiod"].Value); int scriptErrorReportingDelay = int.Parse(Params["scripterrorreportingdelay"].Value); SPDiagnosticsService local = SPDiagnosticsService.Local; local.LogLocation = logDirectory; local.DaysToKeepLogs = logFileCount; local.LogCutInterval = logFileMinutes; local.AllowLegacyTraceProviders = allowLegacyTraceProviders; local.CEIPEnabled = customerExperienceImprovementProgramEnabled; local.ErrorReportingEnabled = errorReportingEnabled; local.ErrorReportingAutomaticUpload = errorReportingAutomaticUploadEnabled; local.DownloadErrorReportingUpdates = downloadErrorReportingUpdatesEnabled; local.LogMaxDiskSpaceUsageEnabled = logMaxDiskSpaceUsageEnabled; local.EventLogFloodProtectionEnabled = eventLogFloodProtectionEnabled; local.ScriptErrorReportingEnabled = scriptErrorReportingEnabled; local.ScriptErrorReportingRequireAuth = scriptErrorReportingRequireAuth; local.EventLogFloodProtectionThreshold = eventLogFloodProtectionThreshold; local.EventLogFloodProtectionTriggerPeriod = eventLogFloodProtectionTriggerPeriod; local.ScriptErrorReportingDelay = scriptErrorReportingDelay; local.Update(); return((int)ErrorCodes.NoError); }
/// <summary> /// n the Page_Load event we are declaring the GridView Object, its event and Datasource /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Page_Load(object sender, EventArgs e) { try { if (!Page.IsPostBack) { txtcreatedBy.Text = SPContext.Current.Web.CurrentUser.Name; txtDate.Text = DateTime.Now.ToString("dd/MM/yyy"); BinData(); } } catch (Exception ex) { //log SPDiagnosticsService diagnosticsService = SPDiagnosticsService.Local; SPDiagnosticsCategory cat = diagnosticsService.Areas["SharePoint Foundation"].Categories["Unknown"]; diagnosticsService.WriteTrace(1, cat, TraceSeverity.Medium, ex.StackTrace, cat.Name, cat.Area.Name); SPUtility.TransferToErrorPage("Some Error occured, Please try after some time. <br/> If problem persists, contact your adminstrator"); } }
/// <summary> /// n the Page_Load event we are declaring the GridView Object, its event and Datasource /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Page_Load(object sender, EventArgs e) { try { const string DATASOURCEID = "gridDS"; gridDS = new ObjectDataSource(); gridDS.ID = DATASOURCEID; gridDS.SelectMethod = "SelectData"; gridDS.TypeName = this.GetType().AssemblyQualifiedName; gridDS.ObjectCreating += new ObjectDataSourceObjectEventHandler(gridDS_ObjectCreating); this.Controls.Add(gridDS); BindDocuments(); } catch (Exception ex) { SPDiagnosticsService diagnosticsService = SPDiagnosticsService.Local; SPDiagnosticsCategory cat = diagnosticsService.Areas["SharePoint Foundation"].Categories["Unknown"]; diagnosticsService.WriteTrace(1, cat, TraceSeverity.Medium, ex.StackTrace, cat.Name, cat.Area.Name); SPUtility.TransferToErrorPage("Some Error occured, Please try after some time. <br/> If problem persists, contact your adminstrator"); } }
public static void WriteLog(string strLogMsg) { SPDiagnosticsService diagSvc = SPDiagnosticsService.Local; diagSvc.WriteTrace(0, new SPDiagnosticsCategory("WET Intranet Theme", TraceSeverity.Unexpected, EventSeverity.Error), TraceSeverity.Unexpected, "WET Intranet Theme for SharePoint 2010: {0}", new object[] { strLogMsg }); }
static GWUtility() { logger = SPDiagnosticsService.Local; logCategory = new SPDiagnosticsCategory("GlasswallLog", TraceSeverity.Verbose, EventSeverity.Information); logErrorCategory = new SPDiagnosticsCategory("GlasswallLog", TraceSeverity.Unexpected, EventSeverity.Error); }
public static void WriteLog(string strLogMsg) { SPDiagnosticsService diagSvc = SPDiagnosticsService.Local; diagSvc.WriteTrace(0, new SPDiagnosticsCategory("CLF3Toolkit", TraceSeverity.Monitorable, EventSeverity.Error), TraceSeverity.Monitorable, "CLF3 Toolkit for SharePoint 2010: {0}", new object[] { strLogMsg }); }
/// <summary> /// This is the method that will execute the WCF service operation across the WCF channel. /// </summary> /// <param name="codeToExecute">A delegate, pointing to the method on the Service Contract interface that you want to run.</param> /// <param name="asProcess">Whether to run as the passed-through identity of the user (supported in claims mode), or the app pool account.</param> /// <typeparam name="TChannel">The type of channel.</typeparam> /// <remarks> /// This is a good place to use an SPMonitoredScope so that you can /// monitor execution times of your service calls. /// This method sets up the load balancer, and calls into the service application. /// If an exception occurs during the load balancer operation, make sure to report it as a failure if it is due to a /// communication issue. Otherwise, if it is an exception in your application logic or execution, do not report the failure /// to ensure that the server is not taken out of the load balancer. /// </remarks> protected void ExecuteOnChannel <TChannel>(CodeToExecuteOnChannel <TChannel> codeToExecute, bool asProcess) { if (codeToExecute == null) { throw new ArgumentNullException("codeToExecute"); } if (this.Proxy == null) { throw new EndpointNotFoundException("Could not find an endpoint because the proxy was not found."); } using (new SPMonitoredScope(string.Format(CultureInfo.InvariantCulture, "{0} - {1}", this.EndPoint, codeToExecute.Method.Name))) { SPDiagnosticsService diagSvc = SPDiagnosticsService.Local; SPServiceLoadBalancer loadBalancer = this.Proxy.LoadBalancer; if (loadBalancer == null) { diagSvc.WriteTrace(0, new SPDiagnosticsCategory("ClubCloud Service", TraceSeverity.Monitorable, EventSeverity.Error), TraceSeverity.Monitorable, "SPServiceLoadBalancerStatus.Failed: {0}", new object[] { "No Load Balancer was available." }); throw new InvalidOperationException("No Load Balancer was available."); } SPServiceLoadBalancerContext loadBalancerContext = loadBalancer.BeginOperation(); try { using (new SPServiceContextScope(this.currentServiceContext)) { ICommunicationObject channel = (ICommunicationObject)this.GetChannel <TChannel>(loadBalancerContext, asProcess); try { codeToExecute((TChannel)channel); channel.Close(); } finally { if (channel.State != CommunicationState.Closed) { channel.Abort(); } } } } catch (TimeoutException ex) { loadBalancerContext.Status = SPServiceLoadBalancerStatus.Failed; diagSvc.WriteTrace(0, new SPDiagnosticsCategory("ClubCloud Service", TraceSeverity.Monitorable, EventSeverity.Error), TraceSeverity.Monitorable, "SPServiceLoadBalancerStatus.Failed: {0}", new object[] { ex.Message }); throw; } catch (EndpointNotFoundException enfex) { loadBalancerContext.Status = SPServiceLoadBalancerStatus.Failed; diagSvc.WriteTrace(0, new SPDiagnosticsCategory("ClubCloud Service", TraceSeverity.Monitorable, EventSeverity.Error), TraceSeverity.Monitorable, "SPServiceLoadBalancerStatus.Failed: {0}", new object[] { enfex.Message }); throw; } catch (ServerTooBusyException stbex) { loadBalancerContext.Status = SPServiceLoadBalancerStatus.Failed; diagSvc.WriteTrace(0, new SPDiagnosticsCategory("ClubCloud Service", TraceSeverity.Monitorable, EventSeverity.Error), TraceSeverity.Monitorable, "SPServiceLoadBalancerStatus.Failed: {0}", new object[] { stbex.Message }); throw; } catch (CommunicationException exception) { if (!(exception is FaultException)) { loadBalancerContext.Status = SPServiceLoadBalancerStatus.Failed; } diagSvc.WriteTrace(0, new SPDiagnosticsCategory("ClubCloud Service", TraceSeverity.Monitorable, EventSeverity.Error), TraceSeverity.Monitorable, "SPServiceLoadBalancerStatus.Failed: {0}", new object[] { exception.Message }); throw; } finally { loadBalancerContext.EndOperation(); } } }
public static void LogMessage(string productName, string message, TraceSeverity traceSeverity, EventSeverity eventSeverity) { SPDiagnosticsService diagService = SPDiagnosticsService.Local; diagService.WriteTrace(0, new SPDiagnosticsCategory(productName, traceSeverity, eventSeverity), traceSeverity, message, new object[] { message }); }
static LoggerUtility() { service = SPDiagnosticsService.Local; category = service.Areas["SharePoint Foundation"].Categories["General"]; }