Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

In CA, Diagnostic Logging, a lot of areas with their categories are listed. When I enumerate these area's in code only three are returned:

  • Business Connectivity Services
  • SharePoint Foundation SharePoint
  • Foundation Search

This is the code I use:

SPDiagnosticsCollection<SPDiagnosticsArea> allAreas = SPDiagnosticsService.Local.Areas;
foreach (SPDiagnosticsArea item in allAreas)
{
    message.Text += "- Area: " + item.Name + "<br />";
} 

Where are the other areas like Access Service, SharePoint Server, Web Content Management and many others?

share|improve this question
add comment

1 Answer 1

up vote 3 down vote accepted

The problem is you are retrieving only SPDiagnosticsService which is provided by SharePoint Foundation out of the box. Keep in mind that these Sharepoint server provides its own Diagnostic service and being extensible other third part components can register their own diagnostic services in Sharepoint farm.

The right way to get all areas is to loop through all services which are derived from SPDiagnosticsServiceBase and then loop through areas as shown below as an example:

SPServiceCollection services = SPFarm.Local.Services;
            var diagServices = from service in services
                               where service is SPDiagnosticsServiceBase
                                   select service;

            foreach (SPDiagnosticsServiceBase service in diagServices)
            {
                Console.WriteLine("Areas of Diagnostic Service: " + service.TypeName);
                SPDiagnosticsCollection<SPDiagnosticsArea> allAreas = service.Areas;
                foreach (SPDiagnosticsArea item in allAreas)
                {
                    Console.WriteLine("Area: " + item.Name);
                 }               
            }
share|improve this answer
    
Thanks! This is exactly what I'm looking for! –  Anita Boerboom Jun 27 '11 at 7:18
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.