日志策略与性能 [英] Logging strategy vs. performance

查看:27
本文介绍了日志策略与性能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个必须支持大量并发请求的 Web 应用程序,我希望它保持足够快的速度.我现在必须实施日志记录策略,我将使用 log4net,但是......我应该记录什么以及如何记录?我的意思是:

I'm developing a web application that has to support lots of simultaneous requests, and I'd like to keep it fast enough. I have now to implement a logging strategy, I'm gonna use log4net, but ... what and how should I log? I mean:

  1. 日志记录如何影响性能?是否可以/推荐使用异步调用进行日志记录?
  2. 使用文本文件还是数据库更好?有条件的可以做吗?例如,默认日志到数据库,如果失败,则切换到文本文件.
  3. 多线程呢?当我使用 log4net 时,我应该关心同步吗?还是开箱即用的线程安全?

在要求中,应用程序应该为每个请求缓存一些东西,我担心这会影响性能.

In the requirements appear that the application should cache a couple of things per request, and I'm afraid of the performance impact of that.

干杯.

推荐答案

  1. 它会让事情变慢 - 做某事比什么都不做需要更多时间.通常是微不足道的数量.别担心.
  2. 登录到文本文件 imo.它们很容易移动/grep/压缩/邮件等,并且您不必担心将数据库关闭的事实记录到数据库中.如果您需要,可以使用附加程序记录到 log4net 的数据库.
  3. 是的,log4net 是线程安全的.
  1. It makes thing slower - doing something takes more time than doing nothing. Usually by a negligible amount. Don't worry about it.
  2. Log to a text file imo. They're easy to move/grep/compress/mail etc. and you don't have to worry about logging to a database the fact that the database is down. There's appenders for logging to a database for log4net if you need that though.
  3. Yes, log4net is thread safe.

拥有日志记录/跟踪非常有价值——至少你应该记录错误,否则你永远不会知道它们.大多数日志记录 API 可让您打开和关闭需要记录的详细信息级别.

Having logging/tracing is extremely valuable - at the very very least you should log errors, or you'll never know about them. Most logging apis let you turn on and off the level of detail you need logged.

不要担心性能,直到它成为问题.这不像你在建造月球火箭,并想通过测试来看看它可以承载多少重量 - 这只是代码,删除充斥着你的日志的日志语​​句,如果它成为一个问题,就重新编译.

Don't worry about performance until it becomes a problem. It's not like you're building moon rockets and wants to see how much weight it can carry by testing it - it's just code, remove the logging statements that flood your logs and recompile if it ever becomes a problem.

这篇关于日志策略与性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆