Quantcast
Channel: SharePoint 2013 - Development and Programming forum
Viewing all articles
Browse latest Browse all 7589

Writing to ULS - understanding category areas?

$
0
0

This is the code that looks fairly standard for creating Category names to write to the ULS:

 
     protected override IEnumerable<SPDiagnosticsArea> ProvideAreas()
        {
            List<SPDiagnosticsArea> areas = new List<SPDiagnosticsArea>
            {
                new SPDiagnosticsArea(DiagnosticAreaName, new List<SPDiagnosticsCategory>
                {
                    new SPDiagnosticsCategory("Connection Info", TraceSeverity.Verbose, EventSeverity.Information),
                    new SPDiagnosticsCategory("Connection Error", TraceSeverity.Unexpected, EventSeverity.Error),
                    new SPDiagnosticsCategory("Command Info", TraceSeverity.Verbose, EventSeverity.Information),
                    new SPDiagnosticsCategory("Command Error", TraceSeverity.Unexpected, EventSeverity.Error),
                })
            };
            return areas;
        }

 

If I understand the structure properly, the first string is the Name of the category, which must be unique. Since the category has assigned severity, then I need a category for each level of severity for each area of the application I want to log from. So I get the somewhat sloppy arrangement shown above. 

If we look at ULS entries from MSFT apps, we see that there are multiple entries that have the same Category label but different severities:

I am guessing that what MSFT did was use this constructor for a Category, so they could have a unique ID for a category, but the display name would be common:

public SPDiagnosticsCategory(
	string name,
	string localizedName,
	TraceSeverity traceDefault,
	EventSeverity eventDefault,
	uint messageId,
	uint categoryId,
	bool hidden,
	bool shadow
)

So something like this:

new SPDiagnosticsCategory("Component_Info", "Common Name", TraceSeverity.Verbose, EventSeverity.Information, 0, 0, false, false),

new SPDiagnosticsCategory("Component_Error", "Common Name", TraceSeverity.Unexpected, EventSeverity.Error, 0, 0, false, false),

[etc]

That's what I am guessing, but I don't like to guess. [grin] Am I missing anything here?

Philo


Philo Janus, MCP Bridging business & Technology: http://www.saintchad.org/ Telecommuter? http://www.homeofficesurvival.com/ Author: Pro InfoPath 2007 & Pro InfoPath 2010 Pro PerformancePoint 2007 Pro SQL Server Analysis Services 2008 Building Integrated Business Intelligence Solutions



Viewing all articles
Browse latest Browse all 7589

Trending Articles