TraceContextRecord.IsWarning Property
.NET Framework (current version)
Gets a value indicating whether the trace record is associated with a TraceContext.Warn method call.
Assembly: System.Web (in System.Web.dll)
Property Value
Type: System.Booleantrue if the TraceContextRecord is associated with the Warn method call; otherwise, false.
The following code example demonstrates how to check the IsWarning property of a TraceContextRecord to determine whether the message that the record contains was written by a Warn or Write method call. If the trace record is a warning message, a different action is taken than if it is an error message.
<%@ Page language="VB" Trace="true" %> <script runat="server"> ' The Page_Load method. Private Sub Page_Load(sender As Object, e As EventArgs) ' Register a handler for the TraceFinished event. AddHandler Trace.TraceFinished, AddressOf OnTraceFinished Try Dim ae As New ArgumentException("Trace Test") Throw ae catch ioe As InvalidOperationException ' You can write an error trace message using the Write method. Trace.Write("Exception Handling", "Exception: Page_Load.", ioe) Catch ae As ArgumentException ' You can write a warning trace message using the Warn method. Trace.Warn("Exception Handling", "Warning: Page_Load.", ae) End Try End Sub ' Page_Load ' A TraceContextEventHandler for the TraceFinished event. Private Sub OnTraceFinished(sender As Object, e As TraceContextEventArgs) Dim r As TraceContextRecord Dim o As Object ' Iterate through the collection of trace records and write ' them to the response stream. For Each o In e.TraceRecords r = CType(o, TraceContextRecord) If r.IsWarning Then Response.Write(String.Format("warning message: {0} <BR>", r.Message)) Else Response.Write(String.Format("error message: {0} <BR>", r.Message)) End If Next End Sub ' OnTraceFinished </script>
.NET Framework
Available since 2.0
Available since 2.0
Show: