0
votes

I am trying to insert Logs via NLOG to azure application insight in console application. But it is not inserting to Application insight where as same code working when using ColouredConsole to show log sin console window.

Tried with programmatically as well, but still logs not going to Application insight.

Reference link : https://github.com/Microsoft/ApplicationInsights-dotnet-logging Under NLOG code followed.

1

1 Answers

0
votes

According to your description, I guess the reason why you face the error target not found is you set the wrong InstrumentationKey.

I suggest you could recheck the InstrumentationKey, which could found in the AI's overview like this:

enter image description here

Then you could use below code to test it.

Install the Microsoft.ApplicationInsights.NLogTarget package

        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();

At last, you could find the record in the search feature.

enter image description here


Update:

Two application use the same AI:

enter image description here