I\'d like to log stuff in my Sharepoint Web Parts, but I want it to go into the ULS. Most examples that I\'ve found log into the Event Log or some other file, but I did not
Try Below Code: (add this reference: using Microsoft.SharePoint.Administration;)
try
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{
SPDiagnosticsService diagSvc = SPDiagnosticsService.Local;
diagSvc.WriteTrace(123456, new SPDiagnosticsCategory("Category_Name_Here", TraceSeverity.Monitorable, EventSeverity.Error), TraceSeverity.Monitorable, "{0}:{1}", new object[] { "Method_Name", "Error_Message"});
});
}
catch (Exception ex)
{
}
Now open uls viewer and filter by your category name.