Avatar of R555B
R555B
 asked on

write to log file columns in vb

Hi All,

Having trouble writing to a logfile and getting the data to dispaly where I want.

What I want to acheive is:
 Untitled.png
But what Im getting is:
srv.png
....So my code isnt writing ot all the columns.
            Dim str As String = "<![LOG[" & message & "]LOG]!><time=""" & Now.ToLongTimeString & """" & " date=""" & Now.ToShortDateString & """ component=""" & component.ToString & """" & " type=""1""" & " Thread=""" & t & """" & ">"
            File.AppendAllText(logfile, str & vbCrLf)

Open in new window


...What Am I missing here ?
.NET Programming

Avatar of undefined
Last Comment
R555B

8/22/2022 - Mon
AndyAinscow

Put a breakpoint on this line:
File.AppendAllText(logfile, str & vbCrLf)
and look at the contents of str.
R555B

ASKER
I've stepped it through the debugger a couple of times...This is the first line that comes out:

"<![LOG[Server Started]LOG]!><time="18:21:32" date="25/02/2015" component="(Main:)" type="1" Thread="8">"

...As far as I can see all the quotes and brackets line up.
AndyAinscow

That makes me think your posted code is fine - the problem is likely by the code you use to fill the grid display.
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
R555B

ASKER
Managed to find some raw data from one of the existing log files on my system. I think maybe the columns are expecting the data to be in a certain format before it will display - As far as I can tell though there is no obvious way to determine what that format is.

I've now managed to get component and date time to appear properly using the following syntax:

Dim d As String = Now.Month & "-" & Now.Day & "-" & Now.Year
Dim str As String = "<![LOG[" & message & "]LOG]!><time=""" & Now.ToLongTimeString & "." & Now.Millisecond & "-60" & """" & " date=""" & d & """ component=""" & component.ToString & """" & " type=""1""" & " Thread=""" & t & """" & """ File=Me

Open in new window


Thread still isnt appearing properly but I think I can probably live with that
AndyAinscow

>>I think maybe the columns are expecting the data to be in a certain format before it will display - As far as I can tell though there is no obvious way to determine what that format is.

Is this some third party tool or something you don't have the code / documentation for?
R555B

ASKER
No - its just appending the text to a standard .log file. Just no way to know what it expects.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
it_saige

Could you provide your method to read the data from the text file and display it in the grid?

-saige-
AndyAinscow

>>No - its just appending the text to a standard .log file. Just no way to know what it expects.

To repeat myself:
Is this some third party tool or something you don't have the code / documentation for?
By that I meant the viewer that you are using to see the log file output.
R555B

ASKER
viewer is cmtrace.exe
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
R555B

ASKER
I've requested that this question be closed as follows:

Accepted answer: 0 points for R555B's comment #a40631371

for the following reason:

Persevered and found the answer
AndyAinscow

Please post just how you solved this or request a delete.
ASKER CERTIFIED SOLUTION
R555B

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.