2

I want to write a Logger/ Bug-Tracker with XML output for my current project. I'm sorry if it should be a duplicate, but the proposals were not useful and I did not found a good google solution too.

1: My first question is about exception safety.

If i use a XmlDocument the loggs are stored in memory till i call save. That means i could lose everything in case of an exception.

If I use a XmlWriter it's not stored in memory (afaik) but I have to close the writer and all elements / nodes which may be a lack in case of an exception too. Can I close and re-open the writer (with the pointer at the end of the document) ?

What's the best solution for an exception-safe XML creation ? (I only need a hint)

2: My second question is about memory usage.

Because it's a tracing tool the output can be very huge. Therefore I can't use XmlDocument. In my opinion the XmlWriter would be the best solution for this. Am i right with this ?

3: My last [minor] question is about time consumption.

Is it a good or bad idea to use a XML file for tracing? How much does it slow down my program ?

I hope you can help me.

EDIT: why do I want to use XML ? later on, my app will run in an "unknown" environment therefore it is neccessary that I can send the log over internet to a server and I have to validate the file (XMLSchema). After this is done I want to convert it to a better readable (and nice formatted) HTML file.

My HTML file

As you can see, this is a much better visualization than XML (this still need some fine tuning but it's functional)

EDIT 2: current state I have made some memory usage measurements. The Logger (currently based on XmlDocument :( ) need ~600mb for 5.000.000 entries. Not the best result but not the worst too.

Best regards Alex

Lucas
  • 3,376
  • 6
  • 31
  • 46
Alex
  • 1,857
  • 3
  • 36
  • 51

3 Answers3

1

For a trace file, do you need the structure of XML? What are your plans for the file once it has been produced; if it is purely for human processing then a text file would be sufficient? That way you can flush after every write. If you want a more queryable file format, could you incorporate a light DB engine? Before changes to MDAC and 64-bit issues with MSAccess file accessing, I used to write to an mdb file. More recently I looked as SQLite and VistaDB.

Is there a specific reason behind you opting for XML?

Paul Eden
  • 338
  • 1
  • 3
  • 10
0

Because this question did not contains a good answer, i have to answer it myself. I've dicided to use a ringbuffer with 10k entries for my log (this seems to be a good number in live use) and i've tried to build a thread and exception safe logbuf (i hope it works).

best regards and thx for all answers

Alex

Alex
  • 1,857
  • 3
  • 36
  • 51
-1

Why do want to roll your own logging solution? There are very mature libraries which can do it "out of the box" afaik.

Christian Sauer
  • 10,351
  • 10
  • 53
  • 85
  • i did not found a good one for my problem. the most frameworks i found are commercial or can't write to xml. if you can name a good one that does what i want it would be nice ;) – Alex Aug 23 '13 at 07:19
  • I personally use Nlog, which can output at least some XML: http://stackoverflow.com/questions/3460266/configuring-nlog-to-log-exceptions-in-an-xml-output But Log4net can output more flexible XML, but I never used it, so I can only point to an article: http://stackoverflow.com/questions/1147103/log4net-xml-output – Christian Sauer Aug 23 '13 at 07:56
  • am i wrong or aren't they designed for xml output ? they can both be configured with xml but i can't see how to output to xml. nevertheless, i don't want to use a framework (only if it's "perfect" for my needs) – Alex Aug 23 '13 at 11:39