使用NLog的Azure Application Insight(未找到目标)

时间:2017-07-14 05:03:40

标签: c# azure nlog azure-application-insights

我正在尝试通过NLOG将日志插入到控制台应用程序中的azure应用程序洞察中。但是,当使用ColouredConsole显示日志控制台窗口时,它不会插入Application insight,因为相同的代码可以工作。

也以编程方式进行尝试,但仍然记录不会进入应用程序洞察。

参考链接: https://github.com/Microsoft/ApplicationInsights-dotnet-logging 在随后的NLOG代码下。

1 个答案:

答案 0 :(得分:0)

根据你的描述,我猜你没有找到错误目标的原因是你设置了错误的InstrumentationKey。

我建议您重新检查一下InstrumentationKey,这可以在AI的概述中找到:

enter image description here

然后你可以使用下面的代码来测试它。

安装Microsoft.ApplicationInsights.NLogTarget包

        var config = new LoggingConfiguration();

        ApplicationInsightsTarget target = new ApplicationInsightsTarget();

        target.InstrumentationKey = "key";
        LoggingRule rule = new LoggingRule("*", NLog.LogLevel.Trace, target);
        config.LoggingRules.Add(rule);

        LogManager.Configuration = config;

        Logger logger = LogManager.GetLogger("Example");

        logger.Trace("trace log message");

        Console.Read();

最后,您可以在搜索功能中找到该记录。

enter image description here

更新

两个应用程序使用相同的AI:

enter image description here