Ok, can someone point out to me why the following code does not work?
In compiles, no errors, but MemoryStream never seems to receive any
data?
Dim theMemory As MemoryStream, _
theListener As TextWriterTraceListener
theMemory = New MemoryStream(4096)
theListener = New TextWriterTraceListener(theMemory)
Trace.AutoFlush = True
Trace.Listeners.Add(theListener)
Trace.WriteLine("Test Memory Stream!")
Dim theReader As StreamReader
Dim theText As String
theReader = New StreamReader(theMemory)
theText = theReader.ReadLine()
Thanks! In Advanced! 3 2331
Perhaps because the Position of the stream is at the end when you try to do
the Readline?
Add theMemory.Position = 0 just before theReader.ReadLine()
"Schorschi" <Sc*******@DSLExtreme.COM> wrote in message
news:21**************************@posting.google.c om... Ok, can someone point out to me why the following code does not work? In compiles, no errors, but MemoryStream never seems to receive any data?
Dim theMemory As MemoryStream, _ theListener As TextWriterTraceListener
theMemory = New MemoryStream(4096) theListener = New TextWriterTraceListener(theMemory)
Trace.AutoFlush = True Trace.Listeners.Add(theListener) Trace.WriteLine("Test Memory Stream!")
Dim theReader As StreamReader Dim theText As String
theReader = New StreamReader(theMemory)
theText = theReader.ReadLine()
Thanks! In Advanced!
Nope, tried that as well.
Talk about answering your own question? LOL. Below is the solution
that works. I am sure others may have different or better ways to
setup a memory based trace-listener, if so maybe they will add to this
message thread?
The idea behind this code was to have a way to capture trace
information for some specialized application-start tasks, that did NOT
incur file I/O, before any of our application configuration settings
are set by .Config file, registry, INI (private profile) or the
commandline, and of course before any of these setting options are
defined by the user. Should the user configure options to disable the
trace information? Then we just toss the queued trace information in
the void, otherwise we redirect it to console, a database, or file
based on the user preference.
Enjoy...
'
'
'
Option Explicit On
Option Strict On
'
Imports System.Windows.Forms.Application
Imports System.IO
Imports System.IO.Path
'
Class ListenerClass
Inherits TraceListener
'
Private theMemory As MemoryStream
Private thePath As String
Private theWriter As StreamWriter
'
Public Sub New()
'
theMemory = New MemoryStream
With theMemory
'
.Position = Nothing
End With
theWriter = New StreamWriter(theMemory)
With theWriter
'
.AutoFlush = True
End With
thePath = Combine(GetDirectoryName(ExecutablePath), _
String.Format("{0} Flush File.LOG",
"MemoryStreamTraceListener"))
File.Delete(thePath)
End Sub
Public Overloads Overrides Sub Write(ByVal theMessage As String)
'
With theWriter
'
.Write(theMessage)
End With
End Sub
Public Overloads Overrides Sub WriteLine(ByVal theMessage As
String)
'
With theWriter
'
.WriteLine(theMessage)
End With
End Sub
Public Overrides Sub Flush()
Dim theFile As FileStream
'
theFile = New FileStream(thePath, FileMode.OpenOrCreate)
With theMemory
'
.WriteTo(theFile)
.SetLength(Nothing)
End With
'
theFile.Close()
End Sub
End Class
Module MainModule
'
Sub Main()
Dim theListener As TraceListener
'
theListener = New ListenerClass
Trace.Listeners.Add(theListener)
Trace.WriteLine("MemoryStreamTraceListener...")
Trace.WriteLine("Egor Its Alive!")
Trace.WriteLine("...Wait, Wait, Wait For It.")
theListener.Flush()
End Sub
End Module This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Geopsaros |
last post by:
Hi!
I have created a custom trace Listener class, called "DBTraceListener"
it works fine when i add it manually in code :
(eg. Trace.listeners.add(new DBTraceListener("myDBListener",...
|
by: Ken |
last post by:
I would like to start using EventLogTraceListener, and am running into
a couple of significant limitations:
1) I have found that there is no way to write EventLog entries with
different...
|
by: Richard |
last post by:
Hi,
I'm having trouble setting up a config file based trace switch & listener. I added an application config file to my console based C# program using the "Add New Application Config File" button...
|
by: Jason |
last post by:
Hi,
I'm a little confused on using a trace listener. I'm doing this (winforms
app btw not web app)
TextWriterTraceListener listener = new
TextWriterTraceListener("TraceOutput.txt",...
|
by: martin |
last post by:
Hi,
I have created an asp.net application as a project, and also another project
that is just a class library.
My asp.net application calls a function in the class library.
I am attempting to...
|
by: Atara |
last post by:
Can I view Trace output when launching a win forms application OUTSIDE
of the ide?
e.g. using switches in the configuration file?
Must I declare a trace listener?
Thanks
Atara.
|
by: Don |
last post by:
When I run the following code, the MemoryStream's Position is always set to
762 instead of 0, which is what I would expect:
Dim bmp As Image
Dim ms As MemoryStream
bmp = New...
|
by: Blake |
last post by:
I am trying to make a trace listener textbox that behaves like the
output window in VS, in that it shows trace messages from all trace
sources.
I created my own listener to write to a textbox...
|
by: boldtbanan |
last post by:
I've created a custom trace listener which I'd like to initialize in
the web.config file of my application. I noticed that I can use the
initializeData attribute to pass a string to the...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
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...
|
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,...
|
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...
|
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...
|
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,...
|
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...
| |