Getting SharePoint ULS Log Location Without Reverting To Literals

The ULS logs are pretty great, especially when you have pre-existing, non-development dependent errors occurring that make absolutely freakin no sense. It’s pretty easy to get the path using the SPDiagnosticsService object.

[csharp]

public string ULSPath()
{
try
{
return SPDiagnosticsService.Local.LogLocation;
}
catch (SqlException sqlEx)
{
SPDiagCommonHelper.TraceException(sqlEx);
}
catch (SPException spEx)
{
SPDiagCommonHelper.TraceException(spEx);
}
return string.Empty;
}
[/csharp]

Share

2 Comments

  1. Vishnu says:

    A good idea when building logging tools for mixed 32bit and 64bit SharePoint farms.

  2. JB says:

    Great article!

    Here you find another nice article about logging with SharePoint:
    http://www.parago.de/2011/01/how-to-implement-a-custom-sharepoint-2010-logging-service-for-uls-and-windows-event-log/

Leave a Reply

Your email address will not be published. Required fields are marked *