TraceContextRecord.IsWarning Propriété
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Obtient une valeur indiquant si l'enregistrement de trace est associé à un appel de méthode Warn.
public:
property bool IsWarning { bool get(); };
public bool IsWarning { get; }
member this.IsWarning : bool
Public ReadOnly Property IsWarning As Boolean
Valeur de propriété
true
si le TraceContextRecord est associé à l'appel de la méthode Warn ; sinon, false
.
Exemples
L’exemple de code suivant montre comment vérifier la IsWarning propriété d’un TraceContextRecord pour déterminer si le message que contient l’enregistrement a été écrit par un Warn appel de méthode ou Write . Si l’enregistrement de trace est un message d’avertissement, une autre action est effectuée que s’il s’agit d’un message d’erreur.
<%@ Page language="c#" Trace="true" %>
<script runat="server">
void Page_Load(object sender, EventArgs e)
{
// Register a handler for the TraceFinished event.
Trace.TraceFinished += new
TraceContextEventHandler(this.OnTraceFinished);
try {
throw new ArgumentException("Trace Test");
}
catch (InvalidOperationException ioe) {
// You can write an error trace message using the Write method.
Trace.Write("Exception Handling", "Exception: Page_Load.", ioe);
}
catch (ArgumentException ae) {
// You can write a warning trace message using the Warn method.
Trace.Warn("Exception Handling", "Warning: Page_Load.", ae);
}
}
// A TraceContextEventHandler for the TraceFinished event.
void OnTraceFinished(object sender, TraceContextEventArgs e)
{
TraceContextRecord r = null;
// Iterate through the collection of trace records and write
// them to the response stream.
foreach(object o in e.TraceRecords)
{
r = (TraceContextRecord)o;
if (r.IsWarning) {
Response.Write(String.Format("warning message: {0} <BR>", r.Message));
}
else {
Response.Write(String.Format("error message: {0} <BR>", r.Message));
}
}
}
</script>
<%@ 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>