0

I have implemented Log4Net for my C# application. I am required to save all the levels of logs. I am currently saving them into a txt file. However, after a while it is getting very hard to find a specific log inside the txt file. So I have to put the output file into a structure. I read about XML and JSON structures, but I could not decide which one is more efficient..

Question: Do you suggest me to use XML or JSON as the output structure, why? Or any other suggestions?

Thanks

Joe Leffrey
  • 183
  • 1
  • 1
  • 5

2 Answers2

0

I would suggest to keep the text format, but configure your log4net for better logging. I always have more than 1 log file.

This is what I suggest:

  1. Have a separated file for error/fatal
  2. Have a log file for all of your logs so if you needed to see the debug/info logs after and before the error you look at that log
  3. Filter your logs to show logs only for specific classes/assembly like if you are using a CRM, it will print a lot of stuff that you don't want. like this one.

  4. Set log4net to put create different files every day (or if you have too much data every 10 MB)

Community
  • 1
  • 1
Ashkan S
  • 10,464
  • 6
  • 51
  • 80
0

XML or JSON will make it even harder to read the logs directly due to the added clutter and escaping. However (that is a big emphasis), if you use JSON, you can then import your logs into ELK (Elastic search, Logstash, Kibana stack). Going through the logs will be a breeze, then. You can use log4net.Ext.Json to produce that JSON.

Like @Ashkan suggests, I'd keep the regular text file locally and stream JSON to a central store, such as ELK.

Robert Cutajar
  • 3,181
  • 1
  • 30
  • 42