Skip to content

Commit

Permalink
Renamed the namespace from Dgmjr.Extensions.Logging to Dgmjr.Logging.…
Browse files Browse the repository at this point in the history
…Extensions to match what I did for the other "Extensions" projects
  • Loading branch information
dgmjr committed Jan 26, 2024
1 parent 993c1b9 commit d32e46d
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 25 deletions.
8 changes: 7 additions & 1 deletion Logging/AutomaticLoggingConfigurator.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
namespace Microsoft.Extensions.DependencyInjection;

using Dgmjr.Configuration.Extensions;

using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.Hosting;

public class AutomaticLoggingConfigurator : IConfigureIHostApplicationBuilder
public class AutomaticLoggingConfigurator
: IConfigureIHostApplicationBuilder,
IConfigureIApplicationBuilder
{
public ConfigurationOrder Order => ConfigurationOrder.VeryEarly;

public void Configure(IHostApplicationBuilder builder)
{
builder.AddLoggingAndApplicationInsightsTelemetry();
}

public void Configure(IApplicationBuilder app) { }
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@
<PackageReference Include="Dgmjr.System.Extensions" ExcludeAssets="ContentFiles" />
<PackageReference Include="Dgmjr.Configuration.Extensions" ExcludeAssets="ContentFiles" />
<PackageReference Include="Azure.Identity" />

<PackageReference Include="OpenTelemetry" />
<PackageReference Include="OpenTelemetry.Exporter.Console" />
<PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" />
<PackageReference Include="OpenTelemetry.Extensions.Hosting" />
<PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" />
<PackageReference Include="OpenTelemetry.Instrumentation.Http" />
<PackageReference Include="OpenTelemetry.Instrumentation.SqlClient" />
</ItemGroup>
<ItemGroup>
<Content Include="LICENSE.md" Pack="true" PackagePath="LICENSE.md" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!--
* Dgmjr.Extensions.Logging.props
* Dgmjr.Logging.Extensions.props
*
* Created: 2024-45-16T05:45:10-05:00
* Modified: 2024-45-16T05:45:10-05:00
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
..\..\..\..\Packages\Versions.Local.props = ..\..\..\..\Packages\Versions.Local.props
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dgmjr.Extensions.Logging", "Dgmjr.Extensions.Logging.csproj", "{C2903F4B-3117-49BB-A9DF-3BB39ECDA2C1}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dgmjr.Logging.Extensions", "Dgmjr.Logging.Extensions.csproj", "{1CFB412D-E8B8-4F49-8330-7B1DA23414B2}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -20,23 +20,23 @@ Global
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{C2903F4B-3117-49BB-A9DF-3BB39ECDA2C1}.Local|Any CPU.ActiveCfg = Local|Any CPU
{C2903F4B-3117-49BB-A9DF-3BB39ECDA2C1}.Local|Any CPU.Build.0 = Local|Any CPU
{C2903F4B-3117-49BB-A9DF-3BB39ECDA2C1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C2903F4B-3117-49BB-A9DF-3BB39ECDA2C1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C2903F4B-3117-49BB-A9DF-3BB39ECDA2C1}.Testing|Any CPU.ActiveCfg = Testing|Any CPU
{C2903F4B-3117-49BB-A9DF-3BB39ECDA2C1}.Testing|Any CPU.Build.0 = Testing|Any CPU
{C2903F4B-3117-49BB-A9DF-3BB39ECDA2C1}.Staging|Any CPU.ActiveCfg = Staging|Any CPU
{C2903F4B-3117-49BB-A9DF-3BB39ECDA2C1}.Staging|Any CPU.Build.0 = Staging|Any CPU
{C2903F4B-3117-49BB-A9DF-3BB39ECDA2C1}.Production|Any CPU.ActiveCfg = Local|Any CPU
{C2903F4B-3117-49BB-A9DF-3BB39ECDA2C1}.Production|Any CPU.Build.0 = Local|Any CPU
{C2903F4B-3117-49BB-A9DF-3BB39ECDA2C1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C2903F4B-3117-49BB-A9DF-3BB39ECDA2C1}.Release|Any CPU.Build.0 = Release|Any CPU
{1CFB412D-E8B8-4F49-8330-7B1DA23414B2}.Local|Any CPU.ActiveCfg = Local|Any CPU
{1CFB412D-E8B8-4F49-8330-7B1DA23414B2}.Local|Any CPU.Build.0 = Local|Any CPU
{1CFB412D-E8B8-4F49-8330-7B1DA23414B2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1CFB412D-E8B8-4F49-8330-7B1DA23414B2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1CFB412D-E8B8-4F49-8330-7B1DA23414B2}.Testing|Any CPU.ActiveCfg = Testing|Any CPU
{1CFB412D-E8B8-4F49-8330-7B1DA23414B2}.Testing|Any CPU.Build.0 = Testing|Any CPU
{1CFB412D-E8B8-4F49-8330-7B1DA23414B2}.Staging|Any CPU.ActiveCfg = Staging|Any CPU
{1CFB412D-E8B8-4F49-8330-7B1DA23414B2}.Staging|Any CPU.Build.0 = Staging|Any CPU
{1CFB412D-E8B8-4F49-8330-7B1DA23414B2}.Production|Any CPU.ActiveCfg = Local|Any CPU
{1CFB412D-E8B8-4F49-8330-7B1DA23414B2}.Production|Any CPU.Build.0 = Local|Any CPU
{1CFB412D-E8B8-4F49-8330-7B1DA23414B2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1CFB412D-E8B8-4F49-8330-7B1DA23414B2}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {DB5DD52F-B426-40D6-AF97-5A7636FEA9C0}
SolutionGuid = {D72166ED-2488-413C-ADF8-E7A85D23BB9F}
EndGlobalSection
EndGlobal
27 changes: 18 additions & 9 deletions Logging/LoggerWebApplicationBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

using Microsoft.ApplicationInsights;
using Microsoft.ApplicationInsights.Extensibility;
using Microsoft.ApplicationInsights.WindowsServer;
// using Microsoft.ApplicationInsights.WindowsServer;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
Expand All @@ -13,6 +13,7 @@
using OpenTelemetry.Metrics;
using OpenTelemetry.Resources;
using OpenTelemetry.Trace;
using OpenTelemetry.Instrumentation.Http;

using global::Azure.Monitor.OpenTelemetry.AspNetCore;
using global::Azure.Identity;
Expand Down Expand Up @@ -64,32 +65,40 @@ IConfiguration configuration
)
{
var appInsightsConnectionString = configuration.GetConnectionString(ApplicationInsights);
TelemetryConfiguration.Active.ConnectionString = appInsightsConnectionString;
// TelemetryConfiguration.Active.ConnectionString = appInsightsConnectionString;
services
.AddOpenTelemetry()
.UseAzureMonitor(options =>
{
options.Credential = new DefaultAzureCredential();
options.ConnectionString = appInsightsConnectionString;
});
})
.ConfigureResource(
resourceBuilder =>
resourceBuilder.AddAttributes(
configuration
.GetSection(OpenTelemetryResourceAttributes)
.Get<Dictionary<string, object>>()!
)
);

#if NET5_0_OR_GREATER
services.AddHttpLogging(
options => configuration.GetRequiredSection(HttpLogging).Bind(options)
);
#endif
services.AddApplicationInsightsTelemetry(configuration.GetSection(ApplicationInsights));
// services.AddApplicationInsightsTelemetry(configuration.GetSection(ApplicationInsights));

services.ConfigureOpenTelemetryTracerProvider(
(sp, builder2) =>
builder2.ConfigureResource(
(_, traceBuilder) =>
{
traceBuilder.ConfigureResource(
resourceBuilder =>
resourceBuilder.AddAttributes(
configuration
.GetSection(OpenTelemetryResourceAttributes)
.Get<Dictionary<string, object>>()!
)
)
);
}
);
return services;
}
Expand Down
Binary file added Logging/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit d32e46d

Please sign in to comment.