一个看似简单的问题,但没有找到最好的方法。
因此,我需要从控制台应用程序记录应用程序事件,该应用程序将在容器内旋转并执行一些工作,然后终止。
如何从内部记录自定义数据?
我尝试过 Azure Monitor 并创建了一个工作区,并在应用程序内使用了 HTTP Data Collector API,但在确定日志存储位置时并没有感到高兴。
有没有一种简单的方法可以登录到 Azure 存储帐户,然后使用 Azure Monitor 来管理事件?
我已经在谷歌上搜索了几个小时,但很多帖子都是 8 年前的帖子了,而且不相关,而且我在现代 Azure 中找不到一个简单的用例。
也许这很简单,我只是看不到
非常收到任何指针或链接!
谢谢 保罗
最佳答案
为什么不使用 Application Insight 自定义事件来跟踪事件?
https://learn.microsoft.com/en-us/azure/azure-monitor/app/api-custom-events-metrics
通过它,您可以使用任何元数据跟踪事件,并在 Azure Application Insights Blade 中检查它们,或者通过 Application Insights SDK 或 Api 访问它们。
您只需创建一个 Application Insight 实例并使用遥测 key 即可完成此操作。
SDK:https://github.com/Microsoft/ApplicationInsights-dotnet
API:https://dev.applicationinsights.io/reference
编写事件的代码示例:
TelemetryClient client = new TelemetryClient();
client .InstrumentationKey = "INSERT YOUR KEY";
client.TrackEvent("SomethingInterestingHappened");
您还可以发送多个字符串值:
tc.TrackEvent("PurchaseOrderSubmitted",
new Dictionary<string, string>()
{
{"CouponCode", "JULY2015" }
}, new Dictionary<string, double>()
{
{"OrderTotal", 68.99 },
{"ItemsOrdered", 5}
});
关于azure - 从 ACI 上的容器内运行的控制台应用程序记录应用程序数据的最佳方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55936489/