【问题标题】:How can I configure Microsoft Insights to store logs如何配置 Microsoft Insights 以存储日志
【发布时间】:2020-12-11 21:32:34
【问题描述】:

我正在尝试在基于 Vue 的应用中配置 Microsoft Insights。我的想法是在那里发送特定的日志,以及我认为相关的信息。 我在 Azure 中创建了资源并获得了它的检测密钥。查看文档我们可以这样加载

import { ApplicationInsights } from '@microsoft/applicationinsights-web'

const appInsights = new ApplicationInsights({ config: {
  instrumentationKey: 'YOUR_INSTRUMENTATION_KEY_GOES_HERE'
} });
appInsights.loadAppInsights();
appInsights.trackPageView();

我的问题是,如何发送特定日志? 我正在寻找类似的东西:

appInsights.log('Info that I want to log');

【问题讨论】:

    标签: javascript azure azure-application-insights


    【解决方案1】:

    你可以使用trackTrace:

    appInsights.trackTrace({message: 'Info that I want to log'});
    

    跟踪通常用于诊断日志记录。如果您想捕获某些业务相关事件,您可以使用trackEvent

    appInsights.trackEvent({
      name: 'some event',
      properties: { // accepts any type
        prop1: 'string',
        prop2: 123.45,
        prop3: { nested: 'objects are okay too' }
      }
    });
    

    自定义属性可以通过名为参数的属性包含在遥测中。这可以使用上面示例中的任何 Track API 来完成。

    更多背景信息请见the GitHub repo

    【讨论】:

    • 工作正确,谢谢!要隔离流量以便仅将来自特定域的流量发送到 Microsoft Insights,我可以使用网络隔离配置还是只允许特定 IP?
    猜你喜欢
    • 1970-01-01
    • 2018-05-25
    • 1970-01-01
    • 2015-08-07
    • 1970-01-01
    • 1970-01-01
    • 2022-06-15
    • 2020-07-20
    • 2015-07-19
    相关资源
    最近更新 更多