Skip to content
This repository was archived by the owner on Jun 10, 2020. It is now read-only.

Enable ILogger by default - #853

Merged
Cijo Thomas (cijothomas) merged 17 commits into
developfrom
cithomas/iloggerbydefault
Mar 29, 2019
Merged

Cijo Thomas (cijothomas) merged 17 commits into
developfrom
cithomas/iloggerbydefault

Conversation

@cijothomas

@cijothomas Cijo Thomas (cijothomas) commented Mar 20, 2019 •

Copy link
Copy Markdown
Contributor

Fix Issue #854

  1. Take dependency of Microsoft.Extensions.Logging.ApplicationInsights for NETSTANDARD2.0
  2. Enables ApplicationInsightsILogger Provider by default for Warning or above logs.
  3. Removes the default DebugLogger - its irrelevant now, as Ilogger logs are now automatically captured.
  4. Add FunctionalTests to validate ILogger integration.
  • I ran Unit Tests locally.

For significant contributions please make sure you have completed the following items:

  • Changes in public surface reviewed

  • Design discussion issue #

  • CHANGELOG.md updated with one line description of the fix, and a link to the original issue.

  • The PR will trigger build, unit tests, and functional tests automatically. If your PR was submitted from fork - mention one of committers to initiate the build for you.
    If you want to to re-run the build/tests, the easiest way is to simply Close and Re-Open this same PR. (Just click 'close pull request' followed by 'open pull request' buttons at the bottom of the PR)

  • Please follow [these] (https://github.com/Microsoft/ApplicationInsights-aspnetcore/blob/develop/Readme.md) instructions to build and test locally.

…nd enable ILogger Provider by default for Warning or above logs.
@cijothomas

Copy link
Copy Markdown
Contributor Author

Sergey Kanzhelev (@SergeyKanzhelev) Pavel Krymets (@pakrym) Ramjot Singh (@RamjotSingh) Please review when you get a chance! thanks in advance.


// By default, all logs Warning or above is captured.
// AddFilter is additive
loggingBuilder.AddFilter<Microsoft.Extensions.Logging.ApplicationInsights.ApplicationInsightsLoggerProvider>("Default", LogLevel.Warning);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we are messing with the ILogger infra here. This can already be done from the config which is read as part of ILogger setup. Hiding this statement this deep in SDK might be non-intuitive.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd be interested in David Fowler (@davidfowl)'s opinion here. Ideally, custom middleware authors would wire up all of the services requisite for their expected behavior. If someone uses AddApplicationInsights, for instance, we'd presume all trace, exception - everything, by default - goes to Application Insights, and that any service wire-ups required for that goal to be "easy" or even "invisible" to the developer.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since users updatng to this new SDK version has not explicitly made a decision to send ILogger logs to AI, i'd like to just sent Warning or above to AI. Without this, we could end up sending too much logs to AI. (negative surprises when billing comes). Since the runtime itself logs using ILogger, we have experienced user complaints about too much AI logs. (#603)

I'd open to all suggestions here. We want to balance between 'easy/auto capture of ILogger logs' and 'too much noise'.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By default, only "Warning" or above LogLevel logs are sent to ApplicationInsightsProvider for all categories. But this can be easily configured by user either in code or using appsettings.json.
I added more description here: #854

@cijothomas

Copy link
Copy Markdown
Contributor Author

Sergey Kanzhelev (@SergeyKanzhelev) can you review?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

generally looks OK

<PackageReference Include="Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel" Version="2.10.0-beta2" />
<PackageReference Include="Microsoft.AspNetCore.Hosting" Version="1.0.2" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="1.0.2" />
<PackageReference Include="Microsoft.AspNetCore.Hosting" Version="1.0.2" />

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will Microsoft.AspNetCore.Hosting.Abstractions be enough?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Likely yes, but i don't want to make un-related changes to this PR. Will revisit all package references in a separate PR.

if (options == null)
{
options = Options.Create(new ApplicationInsightsLoggerOptions());
options = Options.Create(new Microsoft.ApplicationInsights.AspNetCore.Logging.ApplicationInsightsLoggerOptions());

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not be needed. IOptions give a default instance if one does not exist.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess you can ignore this too considering this is old code.


// NetStandard2.0 has a package reference to Microsoft.Extensions.Logging.ApplicationInsights, and
// enables ApplicationInsightsLoggerProvider by default.
#if NETSTANDARD2_0

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I install in Net461 project which one gets picked up? NetStandard or NetFX? My sinking suspicision is that it will pick up NetFX. We can choose to live with it but we should know it (and maybe put a comment here).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NetFX will always "win" over netstandard2.0

<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="2.1.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.1.0" />

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should also be coming from Microsoft.Extensions.Logging.AI so you can skip it here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Likely yes, but i don't want to make un-related changes to this PR. Will revisit all package references in a separate PR.

@cijothomas Cijo Thomas (cijothomas) changed the title {WIP }Take dependency of Microsoft.Extensions.Logging.ApplicationInsights Enable ILogger by default Mar 29, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants