Walkthrough: Populating a Log Message with Additional Context Information
Retired Content |
---|
This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This page may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist. |
The latest Enterprise Library information can be found at the Enterprise Library site. |
This walkthrough demonstrates the steps to populate a LogEntry object with additional information. The Logging Application Block includes classes that populate a hash table with a specific type of information. This walkthrough demonstrates use of the ManagedSecurityContextInformationProvider class.
To reproduce the demonstration
Create a hash table object that will contain the information.
Dictionary<string, object> dictionary = new Dictionary<string, object>();
'Usage Dim _dictionary As New Dictionary(Of String, Object)()
Create a new ManagedSecurityContextInformationProvider object. Call the PopulateDictionary method of this object, passing the Dictionary to it.
ManagedSecurityContextInformationProvider informationHelper = new ManagedSecurityContextInformationProvider(); informationHelper.PopulateDictionary(dictionary);
'Usage Dim informationHelper As New ManagedSecurityContextInformationProvider informationHelper.PopulateDictionary(_dictionary)
Add custom properties to the Dictionary. The following code adds the property named Screen resolution.
int width = Screen.PrimaryScreen.Bounds.Width; int height = Screen.PrimaryScreen.Bounds.Height; string resolution = String.Format("{0}x{1}", width, height); dictionary.Add("Screen resolution", resolution);
'Usage Dim width As Integer = Screen.PrimaryScreen.Bounds.Width Dim height As Integer = Screen.PrimaryScreen.Bounds.Height Dim resolution As String = String.Format("{0}x{1}", width, height) _dictionary.Add("Screen resolution", resolution)
Call the Write method of the Logger class and specify properties to send to the Logging Application Block. The application block will create a log entry containing the extra information.
Logger.Write("Log entry with extra information", dictionary);
'Usage Logger.Write("Log entry with extra information", _dictionary)