Write warning message with Trace.Warn : Trace « Development « ASP.NET Tutorial

Home
ASP.NET Tutorial
1.ASP.Net Instroduction
2.Language Basics
3.ASP.net Controls
4.HTML Controls
5.Page Lifecycle
6.Response
7.Collections
8.Validation
9.Development
10.File Directory
11.Sessions
12.Cookie
13.Cache
14.Custom Controls
15.Profile
16.Configuration
17.LINQ
18.ADO.net Database
19.Data Binding
20.Ajax
21.Authentication Authorization
22.I18N
23.Mobile
24.WebPart
25.XML
ASP.NET Tutorial » Development » Trace 
9.44.5.Write warning message with Trace.Warn
<%@ Page Language="VB" Trace="true"%>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>

<script language="VB" runat="server">
   sub Page_Load(Sender as Object, e as EventArgs
      Trace.Warn("Custom""Page loading...")
      if not Page.IsPostBack then
         Trace.Warn("Custom""No post")
         CreateData()
      end if
   end sub
   
   sub CreateData
      dim source as DataView
      source = Cache("DataView")
      
      if source is nothing then
         dim strConnString as string = "PROVIDER=Microsoft.Jet.OLEDB.4.0;" _
            "DATA SOURCE=" _
            & Server.MapPath("EmployeeDatabase.mdb;")
      
         Trace.Warn("Custom""Creating OleDbDataAdapter...")
         dim objCmd as OleDbDataAdapter = new _
            OleDbDataAdapter("select * from employee", _
            strConnString)
         Trace.Warn("Custom""SQL value: " & _
            objCmd.SelectCommand.CommandText)

         dim ds as DataSet = new DataSet()
         objCmd.Fill(ds, "employee")
         
         source = new DataView(ds.Tables(0))
         Trace.Warn("Custom""Inserting into cache...")
         Cache.Insert("DataView", source)
      
         lblMessage.Text = "Data set created explicitly"
      else
         lblMessage.Text = "Data set retrieved from " & _
            "cache<br>"
      end if

      Trace.Warn("Custom""Binding data...")
      dgData.DataSource = source
      dgData.DataBind()
   end sub
   
   sub ExpireCache(Sender as Object, e as EventArgs)
      Trace.Warn("Custom", _
         "Removing from cache, call CreateData")
      dim dv as dataview = Cache.Remove("DataView")
      CreateData()
   end sub
</script>

<html><body>
   <form runat="server">
      <asp:Label id="lblMessage" runat="server"
         maintainState=false/>
      <asp:Button id="btSubmit" runat="server"
         text="Expire Cache"
         OnClick="ExpireCache"/>
      <asp:DataGrid id="dgData" runat="server" 
         BorderColor="black" GridLines="Vertical" 
         cellpadding="4" cellspacing="0" 
         width="450" Font-Name="Arial" 
         Font-Size="8pt" 
         />
   </form>
</body></html>

File: web.config

<configuration>
   <system.web>
      <trace enabled="true"/>
   </system.web>
</configuration>
9.44.Trace
9.44.1.Trace.IsEnabled
9.44.2.Enable trace in Web.config
9.44.3.Enabling Page Level Tracing
9.44.4.Set Page.Trace.IsEnabled to true (C#)
9.44.5.Write warning message with Trace.Warn
9.44.6.Use Trace.Write to write message (C#)
9.44.7.Trace to a file
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.