Write to Trace log in event action (C#) : Trace « Development « ASP.Net

ASP.Net
1. ADO.net Database
2. Ajax
3. Asp Control
4. Collections
5. Components
6. Data Binding
7. Development
8. File Directory
9. HTML Control
10. Language Basics
11. Login Security
12. Mobile Control
13. Network
14. Page
15. Request
16. Response
17. Server
18. Session Cookie
19. Sitemap
20. Theme Style
21. User Control and Master Page
22. Validation by Control
23. Validation by Function
24. WebPart
25. WPF
26. XML
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
ASP.Net » Development » Trace 
Write to Trace log in event action (C#)

<%@ Page language="c#" src="TraceExample.aspx.cs" AutoEventWireup="false" Inherits="TraceExample" %>
<HTML>
  <body>
    <form id="Form1" method="post" runat="server">
      <DIV style="FONT-SIZE: x-small; WIDTH: 416px; FONT-FAMILY: Verdana; POSITION: relative; HEIGHT: 152px" ms_positioning="GridLayout">
        <asp:Button id="cmdWrite" style="Z-INDEX: 101; LEFT: 16px; POSITION: absolute; TOP: 64px" runat="server" Text="Write Message" Width="128px" Height="24px" Font-Size="X-Small" Font-Names="Verdana"></asp:Button>
        <asp:Label id="Label1" runat="server" style="Z-INDEX: 102; LEFT: 16px; POSITION: absolute; TOP: 16px">A Simple Tracing Example</asp:Label>
        <asp:Button id="cmdWriteCategory" style="Z-INDEX: 103; LEFT: 160px; POSITION: absolute; TOP: 64px" runat="server" Text="Write Message With Category" Width="216px" Height="24px" Font-Size="X-Small" Font-Names="Verdana"></asp:Button>
        <asp:Button id="cmdError" style="Z-INDEX: 104; LEFT: 16px; POSITION: absolute; TOP: 96px" runat="server" Text="Write Exception" Width="128px" Height="24px" Font-Size="X-Small" Font-Names="Verdana"></asp:Button>
        <asp:Button id="cmdSession" style="Z-INDEX: 105; LEFT: 160px; POSITION: absolute; TOP: 96px" runat="server" Text="Add Session Item" Width="136px" Height="24px" Font-Names="Verdana"></asp:Button></DIV>
    </form>
    <BR>
  </body>
</HTML>


<%--
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

  public class TraceExample : System.Web.UI.Page
  {
    protected System.Web.UI.WebControls.Button cmdWrite;
    protected System.Web.UI.WebControls.Label Label1;
    protected System.Web.UI.WebControls.Button cmdWriteCategory;
    protected System.Web.UI.WebControls.Button cmdError;
    protected System.Web.UI.WebControls.Button cmdSession;
  
    private void Page_Load(object sender, System.EventArgs e)
    {
      Trace.IsEnabled = true;
    }

    #region Web Form Designer generated code
    override protected void OnInit(EventArgs e)
    {
      //
      // CODEGEN: This call is required by the ASP.NET Web Form Designer.
      //
      InitializeComponent();
      base.OnInit(e);
    }
    
    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
    {    
      this.cmdWrite.Click += new System.EventHandler(this.cmdWrite_Click);
      this.cmdWriteCategory.Click += new System.EventHandler(this.cmdWriteCategory_Click);
      this.cmdError.Click += new System.EventHandler(this.cmdError_Click);
      this.cmdSession.Click += new System.EventHandler(this.cmdSession_Click);
      this.Load += new System.EventHandler(this.Page_Load);

    }
    #endregion

    private void cmdWrite_Click(object sender, System.EventArgs e)
    {
      
      Trace.Write("About to place an item in session state.");
      Session["Test""Contents";
      Trace.Write("Placed item in session state.");

    }

    private void cmdWriteCategory_Click(object sender, System.EventArgs e)
    {
      Trace.Write("Page_Load""About to place an item in session state.");
      Session["Test""string in session";
      Trace.Write("Page_Load""Placed item in session state.");

    }


    private decimal DivideNumbers(decimal number, decimal divisor)
    {
      return number/divisor;
    }

    private void cmdError_Click(object sender, System.EventArgs e)
    {
      try
      {
        DivideNumbers(50);
      }
      catch (Exception err)
      {
        Trace.Warn("cmdError_Click""Caught Error", err);
      }

    }

    private void cmdSession_Click(object sender, System.EventArgs e)
    {
      DataSet ds = new DataSet();
      Session["MyDataSet"= ds;
    }

  }


--%>
           
       
Related examples in the same category
1. Is trace enabled (VB.net)
2. Trace for loop (VB.net)
3. Write to Trace (VB.net)
4. Use Trace to debug (VB.net)
5. Page trace mode (VB.net)
6. Write trace warn (VB.net)
7. Trace asp calendar event (C#)
8. Page Trace in code behind (C#)
9. Write debug information to trace log (C#)
10. Page Trace (C#)
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.