If you develop a webpart and present it to a Sharepoint website, Sharepoint creates a top-level scope. In this scope, Sharepoint adds a monitor named spcriticaltracecounter to it, this monitor can be used to insert information to the assert and critical events segments of developer dashborad. For example:
If you click the link on the left of the Information bar, you can get more information about the recorded event (the call stack of the current event ). For example:
How to insert information to the assert and critical events Information Section of developer dashboard? We can use adddatatoscope, a static function of the spcriticalcounter class.
When a request is sent, Sharepoint usually automatically loads the spcriticalcounter monitor. Of course, some other monitors will also be loaded with it. The spcriticalcounter class is defined as follows:
Public Sealed Class Spcriticaltracecounter: ispscopedperformancemonitor, idisposable, isp?cemonitor
Spcriticalcounter is a closed class that inherits the ispscopedperformmonitor interface, which we introduced in the previous article.
We can use the followingCodeTo add user information:
Using (Spmonitoredscope scope = New Spmonitoredscope ( " Customer critical " )){
Spcriticaltracecounter. adddatatoscope (
2010 ,
" Critical error " ,
15 ,
" An critical error occurred " );
}
Adddatatoscope static functions are defined as follows:
Public Static Void Adddatatoscope ( Uint Tagid, String Category, Int Tracelevel, String Message );
In the above definition code
The first parameter is a user-defined tag value (custom tag ID) used to identify record items.
The second parameter is a string type, which is the category of this record item)
The third parameter is an int type, which identifies the trace level. Through reflector analysis, we can see that it corresponds to Microsoft. sharepoint. diagnostics. the enumerated definition of ulstracelevel. The values are as follows:
Internal Enum Ulstracelevel
{
High = 20 ,
Medium = 50 ,
Monitorable = 15 ,
Unexpected = 10 ,
Verbose = 100 ,
Verboseex = 200
}
The fourth parameter is the real record information of this record item.