RTF log file

Z

Zytan

I need a log file, and RTF is good since color formatting can help
find the interesting parts. I want something that I can code quick.
Would the easiest way be to write to a hidden RichTextBox, grab the
RTF code from it, and write it to a file on shut down? Likely, I'll
have an option to view the loggin onscreen at the same time, so I may
or may not have a RichTextBox already showing the contents on the
screen. Perhaps I could just make it the same one, but then the log
class needs to be aware of the GUI. I'd rather have it just create
its own RichTextBox internally, *if* that is the best way.

Or, I could just code my own (very simple one) like this, which allows
only basic formatting, which is all I need:
http://www.gamedev.net/reference/programming/features/rtflog/

Any thoughts?

Zytan
 
A

AvdP

Any thoughts?
For logging purposes you can use System.Diagnostic.Trace. It gives you all
the flexibility you need and it can be configured in the application .config
file. You can write plain text to it, so RTF (or HTML, XML, ...) is
possible, though you have to format it yourself.
There are a lot of good examples about System.Diagnostic.Trace, for example
at http://www.15seconds.com/issue/020910.htm

To see the logging onscreen also you could use a FileSystemWatcher on the
logfile. This is a bit tricky, especially when you trace something from the
onscreen logview. You could also derive your own class from TraceListener (I
sent you an example earlier this week ) and provid it with an event to which
the onscreen logview (or an e-mail object, pager object, SMS object, ...)
can subscribe.

Regards,
Anne
 
Z

Zytan

For logging purposes you can use System.Diagnostic.Trace. It gives you all
the flexibility you need and it can be configured in the application .config
file. You can write plain text to it, so RTF (or HTML, XML, ...) is
possible, though you have to format it yourself.
There are a lot of good examples about System.Diagnostic.Trace, for example
at http://www.15seconds.com/issue/020910.htm

Ok, thanks for this link. It's great! I see an error in his first
bit of code, he adds a trace listener, but doesn't remove it,so
subsequent calls to Debug.WriteLine will throw an exception when
attempting to log to the closed file. He needs to add:

Trace.Listeners.Remove(objTraceListener);

Anyway, this is just what I want. thanks.
To see the logging onscreen also you could use a FileSystemWatcher on the
logfile. This is a bit tricky, especially when you trace something from the
onscreen logview. You could also derive your own class from TraceListener (I
sent you an example earlier this week ) and provid it with an event to which
the onscreen logview (or an e-mail object, pager object, SMS object, ...)
can subscribe.

Sounds complicated.

The tracing will be present in the release build, and I can see that
Trace = Debug except that Debug is removed from release, so I will use
Trace. And i want log files to be made always. But, to show them at
the same time? I think your second option is best, to make my own
TraceListener, which can be given a control to log to as well, if
desired.

Thanks!!

Zytan
 
Z

Zytan

For logging purposes you can use System.Diagnostic.Trace.
[snip]
You can write plain text to it, so RTF (or HTML, XML, ...) is
possible, though you have to format it yourself.

Yup, that's too bad, but I guess it's not that big of a deal, as I
said, this link shows how to do it in an easy way:
http://www.gamedev.net/reference/programming/features/rtflog/

But, it'd be nice to not get my hands dirty with that.

Maybe I need a wrapper, that takes a font, color, and string, and will
write them all as RTF to the log file, and passes just the string to
Trace/Debug.

Zytan
 
B

bob

Hi Zytan,
I would tend towards isolating the formatting from the file.
i.e. Make, say, the first char of each line a status char.
When you come to display, read in the file and use the status char to setup
your formatting.
HTH
Bob
 
Z

Zytan

Hi Zytan,
I would tend towards isolating the formatting from the file.
i.e. Make, say, the first char of each line a status char.
When you come to display, read in the file and use the status char to setup
your formatting.
HTH
Bob

Great idea, Bob! This lets me use the tracing classes basically as-
is.

But I still would like to view the log files from outside of the app.
That's mostly how they will be used. I'd have to make a quick little
app to view them properly. With RTF, I wouldn't have any issues.

Zytan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top