473,769 Members | 1,752 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

calling Trace.Write() from classes besides the page class

I've noticed that if you enter the following code in the codebehind
page for an .aspx page, it won't compile because the call to
Trace.Write() is not valid except in methods of a class derived from
System.Web.UI.P age. Two questions:
1) I don't know much about C# but I was under the impression that if
certain classes and functions were available in a namespace (as the
result of a "using" statement at the top of a file), then they were
available throughout the namespace. If Trace.Write() is available as
the result of one of the "using" statements at the top of the
codebehind file, then how is it not available in the MyClass class?
And if Trace.Write() is not imported by any of the "using" statements,
then how is it available to the WebForm1 class?
2) In that case, is there any way to call Trace.Write() statements
from classes other than the page class, to aid in debugging? I added
"using System.Diagnost ics;" to the beginning of the code so that I
could call Trace.Write() from the "MyClass" class, but the output
still didn't show up in the trace.

-Bennett

Here's the code:
*****
using System;
using System.Collecti ons;
using System.Componen tModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.Sess ionState;
using System.Web.UI;
using System.Web.UI.W ebControls;
using System.Web.UI.H tmlControls;

namespace tracetest
{
public class MyClass
{
public MyClass()
{
Trace.Write("My Category", "MyMessage" );
}
}
/// <summary>
/// Summary description for WebForm1.
/// </summary>
public class WebForm1 : System.Web.UI.P age
{

private void Page_Load(objec t sender, System.EventArg s e)
{
Trace.Write("My Category", "MyMessage" );
// Put user code to initialize the page here
}

#region Web Form Designer generated code
override protected void OnInit(EventArg s e)
{
//
// CODEGEN: This call is required by the ASP.NET Web
// Form Designer.
//
InitializeCompo nent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeCompo nent()
{
this.Load += new System.EventHan dler(this.Page_ Load);

}
#endregion
}
}
Nov 17 '05 #1
5 3095
"Steve C. Orr, MCSD" <St***@Orr.ne t> wrote in message news:<uM******* *******@TK2MSFT NGP12.phx.gbl>. ..
Use System.Web.Trac eContext.Write from your classes.

Here's more info:
http://msdn.microsoft.com/library/de...classtopic.asp


I tried calling System.Web.Trac eContext.Write( ) in the constructor of
my class, and then calling the constructor from the Page_Load method,
but it still didn't write to the trace output. When I run the code
below as a codebehind for WebForm1, I see the "MyMessage1 " and
"MyMessage2 " traces, but I don't see the "MyClassCategor y" trace
called from within the constructor. Am I doing something wrong? I
assume I'm supposed to initialize the System.Web.Trac eContext object
by passing HttpContext.Cur rent to the constructor?

Here's the code:

*******
using System;
using System.Collecti ons;
using System.Componen tModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.Sess ionState;
using System.Web.UI;
using System.Web.UI.W ebControls;
using System.Web.UI.H tmlControls;

namespace tracetest
{
public class MyClass
{
public MyClass()
{
System.Web.Trac eContext x =
new
System.Web.Trac eContext(HttpCo ntext.Current);
x.Write("MyClas sCategory", "MyMessage" );
}
}
/// <summary>
/// Summary description for WebForm1.
/// </summary>
public class WebForm1 : System.Web.UI.P age
{

private void Page_Load(objec t sender, System.EventArg s e)
{
MyClass x = new MyClass();
Trace.Write("My Category", "MyMessage1 ");
Trace.Write("My Category", "MyMessage2 ");
// Put user code to initialize the page here
}

#region Web Form Designer generated code
override protected void OnInit(EventArg s e)
{
//
// CODEGEN: This call is required by the ASP.NET
// Web Form Designer.
//
InitializeCompo nent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeCompo nent()
{
this.Load += new System.EventHan dler(this.Page_ Load);

}
#endregion
}
}
Nov 17 '05 #2
"Steve C. Orr, MCSD" <St***@Orr.ne t> wrote in message news:<uM******* *******@TK2MSFT NGP12.phx.gbl>. ..
Use System.Web.Trac eContext.Write from your classes.

Here's more info:
http://msdn.microsoft.com/library/de...classtopic.asp


I tried calling System.Web.Trac eContext.Write( ) in the constructor of
my class, and then calling the constructor from the Page_Load method,
but it still didn't write to the trace output. When I run the code
below as a codebehind for WebForm1, I see the "MyMessage1 " and
"MyMessage2 " traces, but I don't see the "MyClassCategor y" trace
called from within the constructor. Am I doing something wrong? I
assume I'm supposed to initialize the System.Web.Trac eContext object
by passing HttpContext.Cur rent to the constructor?

Here's the code:

*******
using System;
using System.Collecti ons;
using System.Componen tModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.Sess ionState;
using System.Web.UI;
using System.Web.UI.W ebControls;
using System.Web.UI.H tmlControls;

namespace tracetest
{
public class MyClass
{
public MyClass()
{
System.Web.Trac eContext x =
new
System.Web.Trac eContext(HttpCo ntext.Current);
x.Write("MyClas sCategory", "MyMessage" );
}
}
/// <summary>
/// Summary description for WebForm1.
/// </summary>
public class WebForm1 : System.Web.UI.P age
{

private void Page_Load(objec t sender, System.EventArg s e)
{
MyClass x = new MyClass();
Trace.Write("My Category", "MyMessage1 ");
Trace.Write("My Category", "MyMessage2 ");
// Put user code to initialize the page here
}

#region Web Form Designer generated code
override protected void OnInit(EventArg s e)
{
//
// CODEGEN: This call is required by the ASP.NET
// Web Form Designer.
//
InitializeCompo nent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeCompo nent()
{
this.Load += new System.EventHan dler(this.Page_ Load);

}
#endregion
}
}
Nov 17 '05 #3
Hi,

HttpContext.Cur rent.Trace.Writ e(); should do the trick.

Natty Gur, CTO
Dao2Com Ltd.
34th Elkalay st. Raanana
Israel , 43000
Phone Numbers:
Office: +972-(0)9-7740261
Fax: +972-(0)9-7740261
Mobile: +972-(0)58-888377
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 17 '05 #4
Hi,

HttpContext.Cur rent.Trace.Writ e(); should do the trick.

Natty Gur, CTO
Dao2Com Ltd.
34th Elkalay st. Raanana
Israel , 43000
Phone Numbers:
Office: +972-(0)9-7740261
Fax: +972-(0)9-7740261
Mobile: +972-(0)58-888377
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 17 '05 #5
Why is it not possible to use the Trace.Write from System.Diagnost ics ? The
code is simply skipped ... It works in an ASP.NET project, but not in
another ...

Strange ...

Any help appreciated.
Thanks
Didier Kuttel

"Bennett Haselton" <be*****@peacef ire.org> wrote in message
news:e6******** *************** ***@posting.goo gle.com...
I've noticed that if you enter the following code in the codebehind
page for an .aspx page, it won't compile because the call to
Trace.Write() is not valid except in methods of a class derived from
System.Web.UI.P age. Two questions:
1) I don't know much about C# but I was under the impression that if
certain classes and functions were available in a namespace (as the
result of a "using" statement at the top of a file), then they were
available throughout the namespace. If Trace.Write() is available as
the result of one of the "using" statements at the top of the
codebehind file, then how is it not available in the MyClass class?
And if Trace.Write() is not imported by any of the "using" statements,
then how is it available to the WebForm1 class?
2) In that case, is there any way to call Trace.Write() statements
from classes other than the page class, to aid in debugging? I added
"using System.Diagnost ics;" to the beginning of the code so that I
could call Trace.Write() from the "MyClass" class, but the output
still didn't show up in the trace.

-Bennett

Here's the code:
*****
using System;
using System.Collecti ons;
using System.Componen tModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.Sess ionState;
using System.Web.UI;
using System.Web.UI.W ebControls;
using System.Web.UI.H tmlControls;

namespace tracetest
{
public class MyClass
{
public MyClass()
{
Trace.Write("My Category", "MyMessage" );
}
}
/// <summary>
/// Summary description for WebForm1.
/// </summary>
public class WebForm1 : System.Web.UI.P age
{

private void Page_Load(objec t sender, System.EventArg s e)
{
Trace.Write("My Category", "MyMessage" );
// Put user code to initialize the page here
}

#region Web Form Designer generated code
override protected void OnInit(EventArg s e)
{
//
// CODEGEN: This call is required by the ASP.NET Web
// Form Designer.
//
InitializeCompo nent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeCompo nent()
{
this.Load += new System.EventHan dler(this.Page_ Load);

}
#endregion
}
}

Nov 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
3769
by: F. GEIGER | last post by:
I've dev'ed a Python prototype of an app, that besides the internals making it up has a gui. While test-driven dev'ing the app's internals in Python is fun as usual, dev'ing the GUI is not so funny, at least for me. I guess dev'ing a GUI in a test-driven way is not possible, or is it? I'm using wxPython, so if anyone has an idea... For now most of the time I extend and change the gui things, then run it, do the clicks to go thru the...
19
4260
by: Ross A. Finlayson | last post by:
Hi, I hope you can help me understand the varargs facility. Say I am programming in ISO C including stdarg.h and I declare a function as so: void log_printf(const char* logfilename, const char* formatter, ...); Then, I want to call it as so:
2
5265
by: Kevin | last post by:
Hi All, Can someone please tell me what the difference is between DEBUG and TRACE. From what I can see, they are two different classes, but with the same members? Whats the purpose of have two different classes that seem to do the same thing? Thanks alot for any help, much appreciated Kevin
1
4217
by: dhornyak | last post by:
I have been banging my head against the wall for a while now, and can't seem to id the problem. I've been through a ton of posts and the code doesn't seem any different. Can anybody see it? When I call to GetTokenInformation I receive a buffer size (see //HERE... comment in code), but when I let the code continue, asp.net just sits there returning nothing, apparently on the Marshal.AllocHGlobal call. Here's the library function:
0
297
by: Bennett Haselton | last post by:
I've noticed that if you enter the following code in the codebehind page for an .aspx page, it won't compile because the call to Trace.Write() is not valid except in methods of a class derived from System.Web.UI.Page. Two questions: 1) I don't know much about C# but I was under the impression that if certain classes and functions were available in a namespace (as the result of a "using" statement at the top of a file), then they were...
5
2229
by: martin | last post by:
Hi, The trace class seems to me to be very usefull however there are a few features of it that have to confused. I am using visual studio 2003. the IDE will not let me write trace.assert(..) or trace.writeLine(..) or trace.writeif(..)
1
1526
by: H Branyan | last post by:
In the Application_OnStart event in global.asax, my code calls an AlertService which creates a System.Timers.Timer() object. So this service doesn't actually run in conjunction with a specific aspx page, apparently. When the timer's Elapsed event handler fires, it calls some other classes I have written. These classes output some Trace statements that you can view if an aspx page calls them, but I can't seem to figure out where the Trace...
5
3436
by: Nick Flandry | last post by:
I'm running into an Invalid Cast Exception on an ASP.NET application that runs fine in my development environment (Win2K server running IIS 5) and a test environment (also Win2K server running IIS 5), but fails on IIS 6 running on a Win2003 server. The web uses Pages derived from a custom class I wrote (which itself derives from Page) to provide some common functionality. The Page_Load handler the failing webpage starts out like this: ...
3
5075
by: Jerome Cohen | last post by:
AI am trying to call a third-party web service. this service expects an XML fragment that contains the request plus other parameter. adding the web reference created the syntax below(reference.vb). I changed the data type for the structure that contains the XML data from the default "String" to "xml.xmldocument" to enable easy filling of the data. my client code creates an XML document class, fills the data using standard xml dom...
0
9589
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10212
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10047
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9995
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9863
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8872
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7410
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
3962
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3563
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.