In SharePoint 2010 logging can be done both in ULS and Event Logs using SPDiagnosticsService class. The class provides two methods WriteTrace and WriteEvent to write traces and events in ULS and Event Viewer respectively. SharePoint diagnostic logging can be configured using PowerShell or Central administration site. Open CA, go to Monitoring and click on Configure diagnostic logging in Reporting section.
"Error" Event Level and "High" Trace Level.
The full information about different options can be found at
Configure Diagnostic logging.
Following utility class helps create logs in ULS and Event Viewer.
In the above code we are looking for the Out of the box SharePoint Foundation Area and inside that the General Category. The above utility can be used inside the main method as follows:
Here, I have applied filter on ULS Viewer showing only EventID = 101. In order to log into Event Viewer, change the code in main method to following:
We can also create our own Custom Areas and categories by inheriting from SPDiagnosticsServiceBase class.