473,809 Members | 2,733 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Enterprise Library Trace to TextBox

Is there a way to trace exceptions and messages captured with the
Enterprise Library to a custom destination like a text box or any
other control? If not can anyone think of a way to "hack" something
like this?

Mar 15 '07 #1
2 4331
On 15 Mar, 15:03, "Benny" <bennyandli...@ gmail.comwrote:
Is there a way to trace exceptions and messages captured with the
Enterprise Library to a custom destination like a text box or any
other control? If not can anyone think of a way to "hack" something
like this?
This works. I haven't tested whether the threadsafe part works, but
it's a start. Create a new windows forms application, and paste this
into the main form:

using System;
using System.Drawing;
using System.Collecti ons;
using System.Componen tModel;
using System.Windows. Forms;
using System.Data;
using System.Diagnost ics;

namespace WindowsApplicat ion11
{
public delegate void UpdateTextDeleg ate(string pString);

public class Form1 : System.Windows. Forms.Form
{
private System.Windows. Forms.TextBox textBox1;
private System.Windows. Forms.Button button1;
private TextBoxWriter _sw;

private System.Componen tModel.Containe r components = null;

public Form1()
{
InitializeCompo nent();
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Disp ose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code

private void InitializeCompo nent()
{
this.textBox1 = new System.Windows. Forms.TextBox() ;
this.button1 = new System.Windows. Forms.Button();
this.SuspendLay out();
//
// textBox1
//
this.textBox1.L ocation = new System.Drawing. Point(8, 8);
this.textBox1.M ultiline = true;
this.textBox1.N ame = "textBox1";
this.textBox1.S crollBars =
System.Windows. Forms.ScrollBar s.Vertical;
this.textBox1.S ize = new System.Drawing. Size(264, 232);
this.textBox1.T abIndex = 0;
this.textBox1.T ext = "";
//
// button1
//
this.button1.Lo cation = new System.Drawing. Point(8, 248);
this.button1.Na me = "button1";
this.button1.Ta bIndex = 1;
this.button1.Te xt = "button1";
this.button1.Cl ick += new System.EventHan dler(this.butto n1_Click);
//
// Form1
//
this.AutoScaleB aseSize = new System.Drawing. Size(5, 13);
this.ClientSize = new System.Drawing. Size(292, 278);
this.Controls.A dd(this.button1 );
this.Controls.A dd(this.textBox 1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayo ut(false);

_sw = new TextBoxWriter(t extBox1);
Trace.Listeners .Add(new TextWriterTrace Listener(_sw));
Trace.AutoFlush = true;
}
#endregion

[STAThread]
static void Main()
{
Application.Run (new Form1());
}

private void button1_Click(o bject sender, System.EventArg s e)
{
Trace.Indent();
Trace.WriteLine ("Test");
Trace.Unindent( );
}
}
public class TextBoxWriter : System.IO.TextW riter
{
TextBox _textBox;

public TextBoxWriter(S ystem.Windows.F orms.TextBox pTextBox)
{
_textBox = pTextBox;
}
public override void WriteLine(strin g value)
{
object[] x = {value};
if(_textBox.Inv okeRequired)
{
_textBox.Invoke (new UpdateTextDeleg ate(UpdateText) ,new object[]
{value});
}
else
{
_textBox.Text += value + "\r\n";
}

}

public override System.Text.Enc oding Encoding
{
get
{
// TODO: Add TextBoxWriter.E ncoding getter implementation
return null;
}
}
private void UpdateText(stri ng pString)
{
_textBox.Text += pString + "\r\n";
}
}
}

Mar 15 '07 #2
On 15 Mar, 15:58, "DeveloperX " <nntp...@operam ail.comwrote:
On 15 Mar, 15:03, "Benny" <bennyandli...@ gmail.comwrote:
Is there a way to trace exceptions and messages captured with the
Enterprise Library to a custom destination like a text box or any
other control? If not can anyone think of a way to "hack" something
like this?

This works. I haven't tested whether the threadsafe part works, but
it's a start. Create a new windows forms application, and paste this
into the main form:

using System;
using System.Drawing;
using System.Collecti ons;
using System.Componen tModel;
using System.Windows. Forms;
using System.Data;
using System.Diagnost ics;

namespace WindowsApplicat ion11
{
public delegate void UpdateTextDeleg ate(string pString);

public class Form1 : System.Windows. Forms.Form
{
private System.Windows. Forms.TextBox textBox1;
private System.Windows. Forms.Button button1;
private TextBoxWriter _sw;

private System.Componen tModel.Containe r components = null;

public Form1()
{
InitializeCompo nent();
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Disp ose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code

private void InitializeCompo nent()
{
this.textBox1 = new System.Windows. Forms.TextBox() ;
this.button1 = new System.Windows. Forms.Button();
this.SuspendLay out();
//
// textBox1
//
this.textBox1.L ocation = new System.Drawing. Point(8, 8);
this.textBox1.M ultiline = true;
this.textBox1.N ame = "textBox1";
this.textBox1.S crollBars =
System.Windows. Forms.ScrollBar s.Vertical;
this.textBox1.S ize = new System.Drawing. Size(264, 232);
this.textBox1.T abIndex = 0;
this.textBox1.T ext = "";
//
// button1
//
this.button1.Lo cation = new System.Drawing. Point(8, 248);
this.button1.Na me = "button1";
this.button1.Ta bIndex = 1;
this.button1.Te xt = "button1";
this.button1.Cl ick += new System.EventHan dler(this.butto n1_Click);
//
// Form1
//
this.AutoScaleB aseSize = new System.Drawing. Size(5, 13);
this.ClientSize = new System.Drawing. Size(292, 278);
this.Controls.A dd(this.button1 );
this.Controls.A dd(this.textBox 1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayo ut(false);

_sw = new TextBoxWriter(t extBox1);
Trace.Listeners .Add(new TextWriterTrace Listener(_sw));
Trace.AutoFlush = true;

}
#endregion

[STAThread]
static void Main()
{
Application.Run (new Form1());
}

private void button1_Click(o bject sender, System.EventArg s e)
{
Trace.Indent();
Trace.WriteLine ("Test");
Trace.Unindent( );
}
}
public class TextBoxWriter : System.IO.TextW riter
{
TextBox _textBox;

public TextBoxWriter(S ystem.Windows.F orms.TextBox pTextBox)
{
_textBox = pTextBox;
}

public override void WriteLine(strin g value)
{
object[] x = {value};
if(_textBox.Inv okeRequired)
{
_textBox.Invoke (new UpdateTextDeleg ate(UpdateText) ,new object[]
{value});
}
else
{
_textBox.Text += value + "\r\n";
}

}

public override System.Text.Enc oding Encoding
{
get
{
// TODO: Add TextBoxWriter.E ncoding getter implementation
return null;
}
}
private void UpdateText(stri ng pString)
{
_textBox.Text += pString + "\r\n";
}
}

}- Hide quoted text -

- Show quoted text -
With Ent library, you'd want to create a new class

public class TextBoxExceptio nPublisher : IExceptionPubli sher

Then use the TextBoxWriter in the Publish override (and add an entry
to your config in the exception section.

Now the hacky bit, if you can make sure your textbox is assigned to a
static variable on a class that is visible to your ExceptionPublis her
ctor, you can initialise the TextBoxWriter with the textbox from
there. Bit ugly I know. The ExceptionPublis her isn't created until an
exception is raised anyway.

I can try and knock up an example if you need, but I'm running out of
time today. Someone else might have a better idea though.

Mar 15 '07 #3

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

Similar topics

0
1325
by: John Dalberg | last post by:
I am getting the error below many times when I am trying to use the Enterprise Library. The solution seems to be a reboot. I am using Windows 2003 as my dev box. The error also happens with other library blocks. I am in the admin group in the machine and I changed the processmodel in machine.config to SYSTEM. AFAIK, I have elevated my access to the highest.
1
4145
by: David Herbst | last post by:
Enterprise Library Jan 2006 with Visual Studio 2005 on Windows 2000 Server sp4. My custom exception formatter fails with a "Unable to handle exception: 'LoggingExceptionHandler'." exception. When I attached the debugger to the process and stepped into the code it executed without error. In both cases I was running a Debug build, the only difference in the case that works is that I attached the debugger to the same exact binaries....
2
1816
by: zahaby | last post by:
Is it applicable to use the Microsoft Enterprise Library in Logging without using the configuration tool ? I would like to configure and choose the trace listener programmatically . Thanks in advance.
0
5016
by: Eniac | last post by:
Hello, I've started using Enterprise Library 2.0 recently and I've encountered a problem that seems to be ... well... undocumented :) Basically, when I set a Trace Listener (formatted event log to be precise), if i specify the name of a custom event log, the listener won't log in it. I've checked in the registry, the log is there. In the event viewer, I
7
1908
by: galico | last post by:
Hi All, We are having a very strange problem with the above. We have designed an application in ASP.NET 2.0 that uses the enterprise library data application blocks amongst others. We seem to be maxing out the number of connections allowed to the sql server 7 server after running a few large queries through the application? There are less than 1000 rows of data in the database and we are at a loss as to how to fix this, does anyone have...
1
6437
by: Jess Chadwick | last post by:
I am attempting to use the Enterprise Library (Jan 2006) Cryptography block to encrypt a credit card number in my ASP.NET 2.0 Commerce Server application. Everything is configured correctly, as evidenced by the fact that it is running on a production box using the same web.config (but not the same parent web.config). When I call the EncryptSymmetric() method, I get this error: Server Error in '/Store' Application....
1
3565
by: sreedharv | last post by:
Log4Net vs Enterprise Library - Logging Application Block Please list or point to the comparison. My requirements are: - 50 to 70 web servers - Track Machine name - Extract class / method name irrespective of the info type - debug, trace, exception and more - Incoming bad links
0
4613
by: =?Utf-8?B?YW5rMmdv?= | last post by:
Hi, Thanks in advance for reading this. Not sure where to post this question, but I hope someone in here can help. Trying to write to Event Log in VS 2005 (.NET 2.0) using Enterprise Library 2.0 on a XP Pro SP2 Machine
0
2538
by: =?Utf-8?B?UG9sbHkgQW5uYQ==?= | last post by:
Hi, I have previously used EL v 3.1 Exception Handling application block successfully. I thought I would now try to do the same with EL v 4.0. My first experiment was to replace an exception. I created a project and added the following references - 1/ Enterprise Library Exception Handling Application Block v 4.0
0
9721
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
9601
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10376
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...
0
10115
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...
1
7660
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...
0
6881
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5687
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3861
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3014
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.