Is writing server log files to a database a good idea?

后端 未结 6 1959
臣服心动
臣服心动 2020-12-02 10:44

After reading an article about the subject from O\'Reilly, I wanted to ask Stack Overflow for their thoughts on the matter.

6条回答
  •  伪装坚强ぢ
    2020-12-02 11:17

    Log to DB if you can and it doesn't slow down your DB :)

    It's way way way faster to find anything in DB then in log files. Especially if you think ahead what you will need. Logging in db let's you query log table like this:

    select * from logs
    where log_name = 'wcf' and log_level = 'error'
    

    then after you find error you can see the whole path that lead to this error

    select * from logs
    where contextId = 'what you get from previous select' order by timestamp
    

    How will you get this info if you log it in text files?

    Edit: As JonSkeet suggested this answer would be better if I stated that one should consider making logging to db asynchronous. So I state it :) I just didn't need it. For example how to do it you can check "Ultra Fast ASP.NET" by Richard Kiessig.

提交回复
热议问题