Auto stash before merge of "main" and "origin/main"
This commit is contained in:
parent
cb6dd39596
commit
1f675498a2
10 changed files with 148 additions and 30 deletions
|
|
@ -29,19 +29,52 @@ namespace Core.Configurations
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ConfigurationRoot : IConfigurationRoot
|
public class Configuration : IConfiguration
|
||||||
{
|
{
|
||||||
List<IConfigurationProvider> IConfigurationRoot.ConfigurationProviders { get; set; }
|
List<IConfigurationProvider> _providers = [];
|
||||||
|
|
||||||
|
public string this[string key]
|
||||||
|
{
|
||||||
|
get => GetConfiguration(_providers, key);
|
||||||
|
set => throw new NotSupportedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
List<IConfigurationProvider> IConfiguration.ConfigurationProviders
|
||||||
|
{
|
||||||
|
get { return _providers; }
|
||||||
|
set { _providers = value; }
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static string GetConfiguration(IList<IConfigurationProvider> providers, string key)
|
||||||
|
{
|
||||||
|
string value = null;
|
||||||
|
foreach (var provider in providers)
|
||||||
|
{
|
||||||
|
var test = provider.Configuration().SelectToken(ConfigurationBinder.NormalizePath(key));
|
||||||
|
|
||||||
|
if (test != null)
|
||||||
|
value = test.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
public class ConfigurationRoot : Configuration, IConfigurationRoot
|
||||||
|
{
|
||||||
|
List<IConfigurationProvider> IConfiguration.ConfigurationProviders { get; set; }
|
||||||
|
|
||||||
public ConfigurationRoot(List<IConfigurationProvider> configurationProviders)
|
public ConfigurationRoot(List<IConfigurationProvider> configurationProviders)
|
||||||
{
|
{
|
||||||
((IConfigurationRoot)this).ConfigurationProviders = configurationProviders;
|
((IConfiguration)this).ConfigurationProviders = configurationProviders;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
public static class ConfigurationBinder
|
public static class ConfigurationBinder
|
||||||
{
|
{
|
||||||
private static string NormalizePath(string path)
|
public static string NormalizePath(string path)
|
||||||
{
|
{
|
||||||
return path?.Replace(":", ".", StringComparison.Ordinal) ?? string.Empty;
|
return path?.Replace(":", ".", StringComparison.Ordinal) ?? string.Empty;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,10 @@
|
||||||
namespace Core.Configurations
|
namespace Core.Configurations
|
||||||
{
|
{
|
||||||
public interface IConfigurationRoot
|
public interface IConfigurationRoot : IConfiguration { }
|
||||||
{
|
|
||||||
|
public interface IConfiguration
|
||||||
|
{
|
||||||
internal List<IConfigurationProvider> ConfigurationProviders { get; set; }
|
internal List<IConfigurationProvider> ConfigurationProviders { get; set; }
|
||||||
|
string this[string key] { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,4 +4,5 @@ namespace Core.Configurations.SmartConfiguration;
|
||||||
public interface IConfigurationRepository
|
public interface IConfigurationRepository
|
||||||
{
|
{
|
||||||
IEnumerable<AppConfiguration> GetActiveConfigurations();
|
IEnumerable<AppConfiguration> GetActiveConfigurations();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,8 +12,26 @@ namespace Core.Configurations.SmartConfig
|
||||||
{
|
{
|
||||||
return builder.AddProvider(new SmartConfigProvider(builder, configKey, path));
|
return builder.AddProvider(new SmartConfigProvider(builder, configKey, path));
|
||||||
}
|
}
|
||||||
}
|
public static IConfigurationBuilder AddSmartConfig(this IConfigurationBuilder builder, Action<SmartConfigOptions> setupAction)
|
||||||
|
{
|
||||||
|
var options = new SmartConfigOptions();
|
||||||
|
setupAction(options);
|
||||||
|
|
||||||
|
return builder.AddProvider(new SmartConfigProvider(options.GetRepository()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public class SmartConfigOptions
|
||||||
|
{
|
||||||
|
private SmartConfiguration.IConfigurationRepository _repository;
|
||||||
|
|
||||||
|
public SmartConfigOptions UseRepository(SmartConfiguration.IConfigurationRepository repository)
|
||||||
|
{
|
||||||
|
_repository = repository;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
internal SmartConfiguration.IConfigurationRepository GetRepository() => _repository;
|
||||||
|
}
|
||||||
public class SmartConfigProvider : IConfigurationProvider
|
public class SmartConfigProvider : IConfigurationProvider
|
||||||
{
|
{
|
||||||
string _configKey;
|
string _configKey;
|
||||||
|
|
@ -26,6 +44,8 @@ namespace Core.Configurations.SmartConfig
|
||||||
|
|
||||||
public SmartConfigProvider() { }
|
public SmartConfigProvider() { }
|
||||||
|
|
||||||
|
public SmartConfigProvider(SmartConfiguration.IConfigurationRepository configurationProvider)
|
||||||
|
{ }
|
||||||
public SmartConfigProvider(IConfigurationBuilder builder, string configKey, string configurationFilePath)
|
public SmartConfigProvider(IConfigurationBuilder builder, string configKey, string configurationFilePath)
|
||||||
{
|
{
|
||||||
_builder = builder;
|
_builder = builder;
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@
|
||||||
<PackageReference Include="Insight.Database.Providers.PostgreSQL" Version="8.0.1" />
|
<PackageReference Include="Insight.Database.Providers.PostgreSQL" Version="8.0.1" />
|
||||||
<PackageReference Include="Microsoft.ApplicationInsights" Version="2.22.0" />
|
<PackageReference Include="Microsoft.ApplicationInsights" Version="2.22.0" />
|
||||||
<PackageReference Include="Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel" Version="2.22.0" />
|
<PackageReference Include="Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel" Version="2.22.0" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="9.0.1" />
|
||||||
<PackageReference Include="npgsql" Version="9.0.2" />
|
<PackageReference Include="npgsql" Version="9.0.2" />
|
||||||
<PackageReference Include="Seq.Api" Version="2024.3.0" />
|
<PackageReference Include="Seq.Api" Version="2024.3.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,5 @@
|
||||||
using Seq.Api;
|
using System.Text;
|
||||||
using Seq.Api.Client;
|
|
||||||
using Seq.Api.Model.Events;
|
|
||||||
using Seq.Api.Model.LogEvents;
|
|
||||||
using Seq.Api.Model.Shared;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace Core.Telemetry
|
namespace Core.Telemetry
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
using Microsoft.ApplicationInsights.Channel;
|
using Microsoft.ApplicationInsights.Channel;
|
||||||
|
using System.Net.Http.Headers;
|
||||||
|
|
||||||
namespace Core.Telemetry
|
namespace Core.Telemetry
|
||||||
{
|
{
|
||||||
|
|
@ -8,26 +9,38 @@ namespace Core.Telemetry
|
||||||
public ITelemetryChannel _defaultChannel;
|
public ITelemetryChannel _defaultChannel;
|
||||||
static HttpClient _client = new HttpClient();
|
static HttpClient _client = new HttpClient();
|
||||||
|
|
||||||
|
static DebugTelemetryChannel()
|
||||||
|
{
|
||||||
|
_client = new HttpClient()
|
||||||
|
{
|
||||||
|
BaseAddress = new Uri("http://localhost:5341"),
|
||||||
|
Timeout = TimeSpan.FromSeconds(30)
|
||||||
|
};
|
||||||
|
|
||||||
|
_client.DefaultRequestHeaders.Accept.Clear();
|
||||||
|
_client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public DebugTelemetryChannel(string filePath)
|
public DebugTelemetryChannel(string filePath)
|
||||||
{
|
{
|
||||||
_client.BaseAddress = new Uri("http://localhost:5341");
|
|
||||||
_filePath = filePath;
|
_filePath = filePath;
|
||||||
}
|
}
|
||||||
public new void Send(ITelemetry telemetry)
|
public new void Send(ITelemetry telemetry)
|
||||||
{
|
{
|
||||||
var l = new SeqLogger(_client, "", "");
|
var l = new SeqLogger(_client, "", "");
|
||||||
|
|
||||||
//await l.LogToSeq(
|
l.LogToSeq(
|
||||||
// "Bruger {UserId} loggede ind",
|
"Bruger {UserId} loggede ind",
|
||||||
// "Debug",
|
"Debug",
|
||||||
// new Dictionary<string, object> { { "UserId", "12345" }, { "Counter", i++ } }
|
new Dictionary<string, object> { { "UserId", "12345" }, { "Counter", "i++" } }
|
||||||
// );
|
);
|
||||||
|
|
||||||
|
|
||||||
if (telemetry is Microsoft.ApplicationInsights.DataContracts.TraceTelemetry trace)
|
if (telemetry is Microsoft.ApplicationInsights.DataContracts.TraceTelemetry trace)
|
||||||
{
|
{
|
||||||
var severity = trace.SeverityLevel;
|
var severity = trace.SeverityLevel;
|
||||||
Console.WriteLine($"Trace severity: {severity}, Message: {trace.Message}");
|
Console.WriteLine($"Trace severity: {severity}, Message: {trace.Message}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
56
Core/Telemetry/SeqBackgroundService.cs
Normal file
56
Core/Telemetry/SeqBackgroundService.cs
Normal file
|
|
@ -0,0 +1,56 @@
|
||||||
|
using Microsoft.ApplicationInsights;
|
||||||
|
using Microsoft.Extensions.Hosting;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Channels;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Core.Telemetry
|
||||||
|
{
|
||||||
|
public class SeqBackgroundService : BackgroundService
|
||||||
|
{
|
||||||
|
private readonly Channel<string> _channel;
|
||||||
|
private readonly HttpClient _client;
|
||||||
|
private readonly string _url;
|
||||||
|
private readonly TelemetryClient _telemetryClient;
|
||||||
|
|
||||||
|
public SeqBackgroundService(TelemetryClient telemetryClient, Configurations.IConfiguration configuration)
|
||||||
|
{
|
||||||
|
_telemetryClient = telemetryClient;
|
||||||
|
_url = configuration["Seq:Url"]; // eller hvor din Seq URL kommer fra
|
||||||
|
_client = new HttpClient();
|
||||||
|
_channel = Channel.CreateUnbounded<string>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void EnqueueMessage(string message)
|
||||||
|
{
|
||||||
|
_channel.Writer.TryWrite(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
||||||
|
{
|
||||||
|
while (!stoppingToken.IsCancellationRequested)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await foreach (var message in _channel.Reader.ReadAllAsync(stoppingToken))
|
||||||
|
{
|
||||||
|
await _client.PostAsync(_url, new StringContent(message), stoppingToken);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_telemetryClient.TrackException(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task StopAsync(CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
_channel.Writer.Complete();
|
||||||
|
await base.StopAsync(cancellationToken);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -57,10 +57,10 @@ namespace Tests
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public async Task TryDbSetup()
|
public async Task TryDbSetup()
|
||||||
{
|
{
|
||||||
var conn = Container.Resolve<IDbConnection>();
|
//var conn = Container.Resolve<IDbConnection>();
|
||||||
|
|
||||||
var identitySystem = new Database.Core.DDL.SetupIdentitySystem(conn);
|
//var identitySystem = new Database.Core.SetupIdentitySystem(conn);
|
||||||
// identitySystem..CreateSystem("swp");
|
//identitySystem.CreateSystem("swp");
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"AllowedHosts": "*",
|
"AllowedHosts": "*",
|
||||||
"ConnectionStrings": {
|
"ConnectionStrings": {
|
||||||
"DefaultConnection": "Host=192.168.1.57;Port=5432;Database=ptdb01;User Id=sathumper;Password=3911;"
|
"DefaultConnection": "Host=192.168.1.57;Port=5432;Database=sandbox;User Id=postgres;Password=3911;"
|
||||||
},
|
},
|
||||||
"ApplicationInsights": {
|
"ApplicationInsights": {
|
||||||
"ConnectionString": "InstrumentationKey=6d2e76ee-5343-4691-a5e3-81add43cb584;IngestionEndpoint=https://northeurope-0.in.applicationinsights.azure.com/"
|
"ConnectionString": "InstrumentationKey=6d2e76ee-5343-4691-a5e3-81add43cb584;IngestionEndpoint=https://northeurope-0.in.applicationinsights.azure.com/"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue