更新时间:2023-02-14 19:53:38
我找不到有关如何实现在Azure中记录到Blob存储的任何信息.但是,这就是我能够得出的结论:
I was unable to find any information about how logging to blob storage in Azure was implemented. However, this is what I was able to deduce:
I confirmed that disabling the global lock had no effect. Therefore, the performance problem was not directly related to lock contention.
我还确认,如果我打开自动刷新关闭,则不会发生性能问题.
I also confirmed that if I turn AutoFlush off, the performance problem did not occur.
From further cross referencing the source code for the .NET trace API, my conclusion is that it appears that when you enable blob storage for logs, it injects some kind of trace listener into your application (the same way you might add a listener in web.config) and it synchronously writes every trace statement it receives to blob storage.
因此,似乎有几种方法可以解决此问题:
As such, it seems that there are a few ways to workaround this behavior:
我最终做了#3,因为事实证明,我们已经配置了Application Insights,然后打开,我们只是没有意识到它可以处理跟踪日志记录和查询.在禁用跟踪事件的采样之后,我们现在,有一种方法可以轻松地远程查询任何日志语句,并根据任何条件(关键字匹配,特定请求的所有跟踪,特定时间段内的所有跟踪等)获得完整的跟踪.使用Application Insights跟踪侦听器编写日志语句时会产生明显的同步开销,因此应用程序中的任何内容都无需更改(我们可以继续使用.NET跟踪类).另外,由于Application Insights跟踪在跟踪源中非常灵活,因此我们甚至可以根据需要切换到另一个性能更高的日志记录API(例如ETW或log4net),并且Application Insights仍然可以工作.
I ended up doing #3 because, as it turns out, we already had Application Insights configured and on, we just didn't realize it could handle trace logging and querying. After disabling sampling for tracing events, we now have a way to easily query for any log statement remotely and get the full set of traces subject to any criteria (keyword match, all traces for a particular request, all traces in a particular time period, etc.) Moreover, there is no noticeable synchronous overhead to writing log statements with the Application Insights trace listener, so nothing in our application has to change (we can continue using the .NET trace class). As a bonus, since Application Insights tracing is pretty flexible with the tracing source, we can even switch to another higher performance logging API (e.g. ETW or log4net) if needed and Application Insights still works.
最终,您应该考虑使用Application Insights来存储和查询跟踪.首先取决于您为什么想要在Blob存储中存储日志,它可能满足也可能不满足您的需求,但这对我们有用.
Ultimately, you should consider using Application Insights for storing and querying your traces. Depending on why you wanted your logs in blob storage in the first place, it may or may not meet your needs, but it worked for us.