title: Programmatically logging to the Sharepoint ULS
body: <p>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 really find one yet for logging into the ULS.</p>
  
  <p>Annoyingly, Microsoft.SharePoint.Diagnostics Classes are all marked Internal. I did find <a href="http://www.codeplex.com/SharePointOfView/SourceControl/FileView.aspx?itemId=244213&amp;changeSetId=13835" rel="nofollow noreferrer">one example</a> of how to use them anyway through reflection, but that looks really risky and unstable, because Microsoft may change that class with any hotfix they want.</p>
  
  <p>The Sharepoint Documentation wasn't really helpful either - lots of Administrator info about what ULS is and how to configure it, but i have yet to find an example of supported code to actually log my own events.</p>
  
  <p>Any hints or tips?</p>
  
  <p><strong>Edit:</strong> As you may see from the age of this question, this is for SharePoint 2007. In SharePoint 2010, you can use SPDiagnosticsService.Local and then <a href="http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.administration.spdiagnosticsservicebase.writetrace.aspx" rel="nofollow noreferrer">WriteTrace</a>. See the answer from Jürgen below.</p>