add insights support

This commit is contained in:
Nicolas Constant 2020-12-30 03:00:23 -05:00
parent c0bf662f45
commit 44927f5119
No known key found for this signature in database
GPG Key ID: 1E9F677FB01A5688
4 changed files with 20 additions and 2 deletions

View File

@ -0,0 +1,8 @@
namespace BirdsiteLive.Common.Settings
{
public class LogsSettings
{
public string Type { get; set; }
public string InstrumentationKey { get; set; }
}
}

View File

@ -9,6 +9,7 @@
<ItemGroup>
<PackageReference Include="Lamar.Microsoft.DependencyInjection" Version="4.1.0" />
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.16.0" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.10.8" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.1.3" />
</ItemGroup>

View File

@ -38,8 +38,12 @@ namespace BirdsiteLive
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
//services.Configure<InstanceSettings>(Configuration.GetSection("Instance"));
//services.Configure<TwitterSettings>(Configuration.GetSection("Twitter"));
var logsSettings = Configuration.GetSection("Logging").Get<LogsSettings>();
if(string.Equals("insights", logsSettings.Type, StringComparison.OrdinalIgnoreCase))
{
var key = logsSettings.InstrumentationKey;
services.AddApplicationInsightsTelemetry(key);
}
services.AddControllersWithViews();
}
@ -55,6 +59,9 @@ namespace BirdsiteLive
var dbSettings = Configuration.GetSection("Db").Get<DbSettings>();
services.For<DbSettings>().Use(x => dbSettings);
var logsSettings = Configuration.GetSection("Logging").Get<LogsSettings>();
services.For<LogsSettings>().Use(x => logsSettings);
if (string.Equals(dbSettings.Type, DbTypes.Postgres, StringComparison.OrdinalIgnoreCase))
{
var connString = $"Host={dbSettings.Host};Username={dbSettings.User};Password={dbSettings.Password};Database={dbSettings.Name}";

View File

@ -1,5 +1,7 @@
{
"Logging": {
"Type": "none",
"InstrumentationKey": "key",
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",