高负载网站日志记录到文件的方法?
我需要在现有网站中构建点击和转化跟踪(比 IIS 日志文件更具体、更集中)。 我期待相当高的负载。 我已经使用 log4net 进行了调查,特别是 FileAppender 类,但文档明确指出:“这种类型对于多线程来说不安全 ?
有人可以建议一种稳健的方法来解决这种类型的大量日志记录吗 我真的很喜欢 log4net 给我带来的灵活性。 我可以使用 lock
解决缺乏安全多线程的问题吗? 这会引起性能/争用问题吗?
I need to build in click and conversion tracking (more specific and focused than IIS log files) to an existing web site. I am expecting pretty high load. I have investigated using log4net, specifically the FileAppender Class, but the docs explicitly state: "This type is not safe for multithreaded operations."
Can someone suggest a robust approach for a solution for this type of heavy logging? I really like the flexibility log4net would give me. Can I get around the lack of safe multi-threading using lock
? Would this introduce performance/contention concerns?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
使用 syslog 时,您不会遇到任何线程问题。 Syslog,使用 UDP 将日志行发送到日志守护程序(可能位于同一台计算机上)。
如果您有更多正在运行的进程/服务,则效果特别好,因为所有日志行都聚合在 1 个查看工具中。
如果您预计负载非常重,请看看 facebook 的人是如何做到的:http://developers.facebook。 com/scribe/ 您可以使用他们的开源日志工具。 我认为你现在还不会达到他们的负荷,所以在未来一段时间内你应该是安全的!
右
When using syslog, you won't be having any threading issues. Syslog, sends the loglines using UDP to a logdaemon (could potentially be on the same machine).
Works especially great if you have more running processes/services, since all log lines are aggregated in 1 viewing tool.
if you expect really heavy loads, look at how the guys from facebook do it: http://developers.facebook.com/scribe/ You can use their opensource logtool. I don't think you'll hit their kind of load just yet, so you should be safe for some time to come!
R
我也对答案感兴趣,但我会告诉你当我试图找到解决方案时我被告知的内容。
解决这个问题的一个简单方法是使用 SQL 数据库之类的东西。 如果您想要的数据不太适合,您可以让每个页面访问写入它自己的日志文件,然后定期合并日志文件。
不过,我确信有更好的解决方案。
I'm also interested in the answer, but I'll tell you what I was told when I tried to find a solution.
An easy way around it would be to use something like an SQL database. If the data you want isn't well suited for that, you could have each page access write it's own log file and then periodically merge the log files.
However, I'm sure there's a better solution.
您可以查看 Microsoft Enterprise Library 中提供的日志记录应用程序块。 它提供了一整套不同类型的记录器,以及一个方便的 GUI 配置器,您可以将其指向 app.config\web.config 以便对其进行修改。 因此您无需亲自筛选 XML。
这里有一个关于如何开始使用它的很好的教程的链接:
http://elegantcode.com/2009/01/20/enterprise-library-logging-101/
You could check out the Logging Application Block available in the Microsoft Enterprise Library. It offers a whole host of different types of loggers, as well as a handy GUI configurator that you can point to your app.config\web.config in order to modify it. So there's not need to sift through the XML yourself.
Here's a link to a nice tutorial on how to get started with it:
http://elegantcode.com/2009/01/20/enterprise-library-logging-101/
虽然 FileAppender 本身对于日志记录可能不安全,但我当然期望通过 log4net 到它的正常访问路由是线程安全的。
从 常见问题解答:
换句话说,要么主 log4net 框架执行了足够的锁定,要么它有一个专用的日志线程为日志消息的生产者/消费者队列提供服务。
任何非线程安全的日志框架都不会长期存在。
While FileAppender itself may not be safe for logging, I'd certainly expect the normal access routes to it via log4net to be thread-safe.
From the FAQ:
In other words, either the main log4net framework does enough locking, or it has a dedicated logging thread servicing a producer/consumer queue of log messages.
Any logging framework which wasn't thread-safe wouldn't survive for long.