Skip to content

Riyaz's Innovative Solutions Blog

Your one stop consultant for Digital Workplace

  • About

Writing Diagnostic Information to Event Log / SharePoint Log

January 30, 2015January 30, 2015 ~ msmriyaz

Sample Method call:

LogMessage(string.Format("SP group '{0}' does not have enough permission.", NewItServiceAdminGroupName), EventLogEntryType.Error, true, "Feature Activation", EventSeverity.ErrorCritical, TraceSeverity.Unexpected);

Method used:

/// <summary> /// Log message to event log and SharePoint log. /// </summary> /// <param name="message">Message to log.</param> /// <param name="eventLogEntryType">Specifies the type of event entry log.</param> /// <param name="logInSharePointLog">Flag to include SharePoint log entry as well.</param> /// <param name="eventCategoryName">SharePoint event category name.</param> /// <param name="eventSeverity">SharePoint event severity.</param> /// <param name="traceSeverity">SharePoint trace severity.</param> public static void LogMessage(string message, EventLogEntryType eventLogEntryType, bool logInSharePointLog, string eventCategoryName, EventSeverity eventSeverity, TraceSeverity traceSeverity) { SPSecurity.RunWithElevatedPrivileges(delegate() { const string sourceName = "SharePoint Custom Solutions"; const string logName = "Application"; if (!EventLog.SourceExists(sourceName)) { EventLog.CreateEventSource(sourceName, logName); } // Writing to -> Windows Logs/Application EventLog.WriteEntry(sourceName, message, eventLogEntryType, 1001, 100); if (logInSharePointLog) { SPDiagnosticsService diagnosticsService = SPDiagnosticsService.Local; SPDiagnosticsCategory categoryOfTheTrace = diagnosticsService.Areas["SharePoint Foundation"].Categories["Unknown"]; SPDiagnosticsService.Local.WriteTrace(1, categoryOfTheTrace, traceSeverity, message, categoryOfTheTrace.Name, categoryOfTheTrace.Area.Name); } }); }

Windows Server Event Viewer Output:

image

SharePoint ULS Viewer Output:

image

Possible values for TraceSeverity & EventSeverity:

https://msdn.microsoft.com/en-us/library/microsoft.sharepoint.administration.traceseverity(v=office.12).aspx

 

EventSeverity

Event Severity

Share this:

  • Email
  • Print
  • Facebook
  • Reddit
  • Twitter

Like this:

Like Loading...

Related

Posted in CSOM, Development, Document Library, Environment, Feature Activate, Managed Metadata Service, MOSS 2007, News, O365, Office 365, Permission, Scrum, Security, SharePoint-2010, SharePoint-2013, Taxonomy 20102013DiagnositcEventLogLog fileSharePoint log filetechnical guidanceusers group

Published by msmriyaz

Software Solutions Architect. Passionate about helping organisations enabling innovative software solutions to drive adoption. View all posts by msmriyaz

Post navigation

‹ PreviousSharePoint Developer box configured with email send/receive capability using SMTP Service + Visendo SmtpExtender
Next ›Mapping an image to use within SharePoint

Recent Posts

  • NVM is a life saver when you want to work with multiple version of node.js
  • Online Unicode characters Reference
  • Innovative Enablement of UX Drives Adoption
  • The IT as a Utility
  • Creating and Configuring Resource Mailboxes

Author Grid

Top Clicks

  • nodejs.org/en/download/re…

myTweets

  • Interesting, I guess it is safe to assume that @MKBHD everyday phone is #Pixel4XL #smartphone #Google https://t.co/xKJmyBuiFO 2 weeks ago
  • Only in #bananarepublic you get red bills for amount excessively paid. Computer solutions at its best. #SriLanka… twitter.com/i/web/status/1… 2 months ago
  • Ha ha, commuters were calling North Shore Line this morning #notsureline @NSWTrainInfo @TransportforNSW 2 months ago
  • NVM is a life saver when you want to work with multiple version of node.js geektalk.tech/2019/05/29/nvm… https://t.co/HVObNkybIS 6 months ago
  • Online Unicode characters Reference geektalk.tech/2019/05/26/onl… 6 months ago
Follow @msmriyaz

Search Topic

Follow Riyaz's Innovative Solutions Blog on WordPress.com

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 98 other followers

myRSS

  • RSS - Posts
  • RSS - Comments

myTags

2010 account Add administration application Azure Branding bulk Cloud collection configure configuring content create Custom Customization data view web part Date debug Development Document e-mail email enable environment Error feature FILE Hotfix information install invoke library List Manage Master page migration Navantis Office 365 Outbound Page path Permission Picture policy PowerShell provisioning PS Reference script Server service SharePoint SharePoint 2010 SharePoint Designer site site collection SMTP Solution template test tfs Tool Update user id utility v4.master versioning View Virtual Visual Studio Visual Studio 2010 web wsp xslt
Powered by WordPress.com.
loading Cancel
Post was not sent - check your email addresses!
Email check failed, please try again
Sorry, your blog cannot share posts by email.
%d bloggers like this: