Just to elaborate on Wictor's answer, his example will log 'Unknown' to the Area column.
SPDiagnosticsCategory has an 'Area' property, but unfortunately its protection level is set to internal.
However, you can set it using some reflection code. Listed below is an example of how to write to the SharePoint 2010 trace log using reflection. I use it in a generic library that allows logging to both the SharePoint 2007 and 2010 trace logs. In that case reflection must be used as the library is compiled against the 2007 version of Microsoft.SharePoint.dll.
/// <summary>
/// Write to the SharePoint 2010 trace log
/// </summary>
/// <param name="tag">The Tag to write to the log.</param>
/// <param name="level">The Trace Severity Level to write to the log.</param>
/// <param name="area">The name of the product to write to the log.</param>
/// <param name="categoryName">The name of the category to write to the log.</param>
/// <param name="message">The actual message to write</param>
public static void WriteTraceSP2010(uint tag, TraceSeverity level, string area, string categoryName, string message)
{
string traceSeverityName = null;
string eventSeverityName = "None";
// ** Map the SP2007 TraceSeverity Enum to the SP2010 ones
switch (level)
{
case TraceSeverity.Assert:
case TraceSeverity.CriticalEvent:
case TraceSeverity.Exception:
case TraceSeverity.Unexpected:
case TraceSeverity.WarningEvent:
traceSeverityName = "Unexpected";
break;
case TraceSeverity.InformationEvent:
case TraceSeverity.Unassigned:
traceSeverityName = "Medium";
break;
default:
// ** Anything else is mapped 1:1
traceSeverityName = level.ToString();
break;
}
// ** Load the SharePoint 2010 version of Microsoft.SharePoint
Assembly assembly = Assembly.Load("Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c");
// ** Get SPDiagnosticsService.Local
Type spDiagnosticsServiceType = assembly.GetType("Microsoft.SharePoint.Administration.SPDiagnosticsService");
object service = spDiagnosticsServiceType.GetProperty("Local", BindingFlags.Static | BindingFlags.Public).GetValue(
Activator.CreateInstance(spDiagnosticsServiceType), null);
// ** Get the correct enum value
Type eventSeverityType = assembly.GetType("Microsoft.SharePoint.Administration.EventSeverity");
object eventSeverity = eventSeverityType.GetField(eventSeverityName).GetValue(null);
Type traceSeverityType = assembly.GetType("Microsoft.SharePoint.Administration.TraceSeverity");
object traceSeverity = traceSeverityType.GetField(traceSeverityName).GetValue(null); ;
// ** Create a new DiagnosticsCategory
Type diagnosticsCategoryType = assembly.GetType("Microsoft.SharePoint.Administration.SPDiagnosticsCategory");
Object diagnosticsCategory = Activator.CreateInstance(diagnosticsCategoryType, new Object[] { categoryName,
traceSeverity, eventSeverity});
// ** Set the area
Type diagnosticsAreaType = assembly.GetType("Microsoft.SharePoint.Administration.SPDiagnosticsArea");
Object diagnosticsArea = Activator.CreateInstance(diagnosticsAreaType, new Object[] { area, null });
diagnosticsCategoryType.GetProperty("Area").SetValue(diagnosticsCategory, diagnosticsArea, null);
// ** Execute the WriteTrace method
spDiagnosticsServiceType.GetMethod("WriteTrace").Invoke(service, new object[] { tag, diagnosticsCategory,
traceSeverity, message, null });
}
Note that the TraceSeverity enumeration is the one used in MSDN's SharePoint 2007 ULS sample code.
More information can be found on the MSDN web site.