More work on SeqBackgroundService, next step is tests for it.
This commit is contained in:
parent
a139b1ad08
commit
67207cf90b
27 changed files with 237 additions and 190 deletions
|
|
@ -1,3 +1,4 @@
|
|||
using Application;
|
||||
using Autofac.Extensions.DependencyInjection;
|
||||
|
||||
var host = Host.CreateDefaultBuilder(args)
|
||||
|
|
@ -6,7 +7,7 @@ var host = Host.CreateDefaultBuilder(args)
|
|||
{
|
||||
webHostBuilder
|
||||
.UseContentRoot(Directory.GetCurrentDirectory())
|
||||
.UseStartup<PlanTempus.Startup>();
|
||||
.UseStartup<Startup>();
|
||||
})
|
||||
.Build();
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
using Core.Configurations.JsonConfigProvider;
|
||||
using Core.Configurations;
|
||||
|
||||
namespace PlanTempus
|
||||
namespace Application
|
||||
{
|
||||
public class Startup
|
||||
{
|
||||
|
|
@ -28,7 +28,7 @@ namespace PlanTempus
|
|||
|
||||
services.Configure<Microsoft.AspNetCore.Mvc.Razor.RazorViewEngineOptions>(options =>
|
||||
{
|
||||
options.ViewLocationExpanders.Add(new Application.Common.ComponentsViewLocationExpander());
|
||||
options.ViewLocationExpanders.Add(new Common.ComponentsViewLocationExpander());
|
||||
});
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,4 @@
|
|||
using Core.Configurations.SmartConfigProvider;
|
||||
|
||||
namespace Core.Configurations.SmartConfiguration;
|
||||
namespace Core.Configurations.SmartConfigProvider;
|
||||
public interface IConfigurationRepository
|
||||
{
|
||||
string ConnectionString { get; set; }
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
using System.Data;
|
||||
using Core.Configurations.SmartConfiguration;
|
||||
using Insight.Database;
|
||||
|
||||
namespace Core.Configurations.SmartConfigProvider.Repositories;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
namespace Core.Configurations.SmartConfig
|
||||
namespace Core.Configurations.SmartConfigProvider
|
||||
{
|
||||
/// <summary>
|
||||
/// Extension methods for adding smart configuration providers to IConfigurationBuilder.
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
namespace Core.Configurations.SmartConfig
|
||||
namespace Core.Configurations.SmartConfigProvider
|
||||
{
|
||||
/// <summary>
|
||||
/// Configuration options for setting up smart configuration providers.
|
||||
|
|
@ -6,7 +6,7 @@ namespace Core.Configurations.SmartConfig
|
|||
/// </summary>
|
||||
public class SmartConfigOptions
|
||||
{
|
||||
private SmartConfiguration.IConfigurationRepository _repository;
|
||||
private IConfigurationRepository _repository;
|
||||
internal string _configKey;
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -17,7 +17,7 @@ namespace Core.Configurations.SmartConfig
|
|||
public SmartConfigOptions UsePostgres(string configKey)
|
||||
{
|
||||
_configKey = configKey;
|
||||
_repository = new Configurations.SmartConfigProvider.Repositories.PostgresConfigurationRepository();
|
||||
_repository = new Repositories.PostgresConfigurationRepository();
|
||||
return this;
|
||||
}
|
||||
/// <summary>
|
||||
|
|
@ -34,12 +34,12 @@ namespace Core.Configurations.SmartConfig
|
|||
/// </summary>
|
||||
/// <param name="repository">The configuration repository to use</param>
|
||||
/// <returns>The configuration options instance for method chaining</returns>
|
||||
public SmartConfigOptions UseRepository(SmartConfiguration.IConfigurationRepository repository)
|
||||
public SmartConfigOptions UseRepository(IConfigurationRepository repository)
|
||||
{
|
||||
_repository = repository;
|
||||
return this;
|
||||
}
|
||||
|
||||
internal SmartConfiguration.IConfigurationRepository GetRepository() => _repository;
|
||||
internal IConfigurationRepository GetRepository() => _repository;
|
||||
}
|
||||
}
|
||||
|
|
@ -3,7 +3,7 @@ using Core.Exceptions;
|
|||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace Core.Configurations.SmartConfig
|
||||
namespace Core.Configurations.SmartConfigProvider
|
||||
{
|
||||
/// <summary>
|
||||
/// Configuration provider that loads configuration from a smart configuration source (e.g. database).
|
||||
|
|
@ -22,7 +22,7 @@ namespace Core.Configurations.SmartConfig
|
|||
string _path;
|
||||
IConfigurationBuilder _builder;
|
||||
|
||||
Newtonsoft.Json.Linq.JObject _configuration;
|
||||
JObject _configuration;
|
||||
SmartConfigOptions _smartConfigOptions;
|
||||
|
||||
public SmartConfigProvider() { }
|
||||
|
|
@ -59,7 +59,7 @@ namespace Core.Configurations.SmartConfig
|
|||
using (StreamReader file = File.OpenText(_path))
|
||||
using (JsonTextReader reader = new JsonTextReader(file))
|
||||
{
|
||||
var jsonConfiguration = (Newtonsoft.Json.Linq.JObject)Newtonsoft.Json.Linq.JToken.ReadFrom(reader);
|
||||
var jsonConfiguration = (JObject)JToken.ReadFrom(reader);
|
||||
|
||||
_connectionString = jsonConfiguration.SelectToken($"ConnectionStrings.{_configKey}")?.ToString();
|
||||
}
|
||||
|
|
@ -77,7 +77,7 @@ namespace Core.Configurations.SmartConfig
|
|||
|
||||
}
|
||||
|
||||
public Newtonsoft.Json.Linq.JObject Configuration()
|
||||
public JObject Configuration()
|
||||
{
|
||||
return _configuration;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,7 +22,6 @@
|
|||
<ItemGroup>
|
||||
<Folder Include="Configurations\AzureAppConfigurationProvider\" />
|
||||
<Folder Include="Configurations\PostgresqlConfigurationBuilder\" />
|
||||
<Folder Include="Logging\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
|||
81
Core/Logging/SeqBackgroundService.cs
Normal file
81
Core/Logging/SeqBackgroundService.cs
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
using Core.Telemetry;
|
||||
using Microsoft.ApplicationInsights;
|
||||
using Microsoft.ApplicationInsights.Channel;
|
||||
using Microsoft.ApplicationInsights.DataContracts;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
|
||||
namespace Core.Logging
|
||||
{
|
||||
public class SeqBackgroundService : BackgroundService
|
||||
{
|
||||
private readonly IMessageChannel<ITelemetry> _messageChannel;
|
||||
private readonly TelemetryClient _telemetryClient;
|
||||
private readonly SeqLogger _seqLogger;
|
||||
|
||||
public SeqBackgroundService(TelemetryClient telemetryClient,
|
||||
IMessageChannel<ITelemetry> messageChannel,
|
||||
SeqLogger seqlogger)
|
||||
{
|
||||
_telemetryClient = telemetryClient;
|
||||
_messageChannel = messageChannel;
|
||||
_seqLogger = seqlogger;
|
||||
|
||||
}
|
||||
|
||||
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
||||
{
|
||||
try
|
||||
{
|
||||
while (!stoppingToken.IsCancellationRequested)
|
||||
await foreach (var telemetry in _messageChannel.Reader.ReadAllAsync(stoppingToken))
|
||||
{
|
||||
try
|
||||
{
|
||||
switch (telemetry)
|
||||
{
|
||||
case ExceptionTelemetry et:
|
||||
await _seqLogger.LogAsync(et);
|
||||
break;
|
||||
|
||||
case TraceTelemetry et:
|
||||
await _seqLogger.LogAsync(et);
|
||||
break;
|
||||
|
||||
case DependencyTelemetry et:
|
||||
await _seqLogger.LogAsync(et);
|
||||
break;
|
||||
|
||||
case RequestTelemetry et:
|
||||
await _seqLogger.LogAsync(et);
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new NotSupportedException(telemetry.GetType().Name);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
throw;
|
||||
//_telemetryClient.TrackException(ex); this is disabled for now, we need to think about the channel structure first
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (ex is not OperationCanceledException)
|
||||
{
|
||||
_telemetryClient.TrackException(ex);
|
||||
throw;
|
||||
}
|
||||
|
||||
_telemetryClient.TrackTrace("Service shutdown started");
|
||||
}
|
||||
}
|
||||
|
||||
public override async Task StopAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
_messageChannel.Dispose();
|
||||
await base.StopAsync(cancellationToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
7
Core/Logging/SeqConfiguration.cs
Normal file
7
Core/Logging/SeqConfiguration.cs
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
using Microsoft.ApplicationInsights.DataContracts;
|
||||
using System.Text;
|
||||
|
||||
namespace Core.Logging
|
||||
{
|
||||
public record SeqConfiguration(string IngestionEndpoint, string ApiKey, string Environment);
|
||||
}
|
||||
29
Core/Logging/SeqHttpClient.cs
Normal file
29
Core/Logging/SeqHttpClient.cs
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
|
||||
namespace Core.Logging
|
||||
{
|
||||
public class SeqHttpClient
|
||||
{
|
||||
HttpClient _httpClient;
|
||||
|
||||
public SeqHttpClient(SeqConfiguration seqConfiguration, HttpMessageHandler httpMessageHandler)
|
||||
{
|
||||
_httpClient = new HttpClient(httpMessageHandler)
|
||||
{
|
||||
BaseAddress = new Uri(seqConfiguration.IngestionEndpoint),
|
||||
Timeout = TimeSpan.FromSeconds(30)
|
||||
};
|
||||
|
||||
_httpClient.DefaultRequestHeaders.Accept.Clear();
|
||||
_httpClient.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
|
||||
if (seqConfiguration.ApiKey != null)
|
||||
_httpClient.DefaultRequestHeaders.Add("X-Seq-ApiKey", seqConfiguration.ApiKey);
|
||||
}
|
||||
|
||||
public SeqHttpClient(SeqConfiguration seqConfiguration) : this(seqConfiguration, new HttpClientHandler()) { }
|
||||
|
||||
public async Task<HttpResponseMessage> SendAsync(HttpRequestMessage httpRequestMessage, CancellationToken cancellationToken)
|
||||
{
|
||||
return await _httpClient.SendAsync(httpRequestMessage, cancellationToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,39 +1,8 @@
|
|||
using Microsoft.ApplicationInsights.Channel;
|
||||
using Microsoft.ApplicationInsights.DataContracts;
|
||||
using Microsoft.ApplicationInsights.DataContracts;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace Core.Telemetry
|
||||
namespace Core.Logging
|
||||
{
|
||||
public record SeqConfiguration(string IngestionEndpoint, string ApiKey, string Environment);
|
||||
|
||||
|
||||
public class SeqHttpClient
|
||||
{
|
||||
HttpClient _httpClient;
|
||||
|
||||
public SeqHttpClient(SeqConfiguration seqConfiguration, HttpMessageHandler httpMessageHandler)
|
||||
{
|
||||
_httpClient = new HttpClient(httpMessageHandler)
|
||||
{
|
||||
BaseAddress = new Uri(seqConfiguration.IngestionEndpoint),
|
||||
Timeout = TimeSpan.FromSeconds(30)
|
||||
};
|
||||
|
||||
_httpClient.DefaultRequestHeaders.Accept.Clear();
|
||||
_httpClient.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
|
||||
if (seqConfiguration.ApiKey != null)
|
||||
_httpClient.DefaultRequestHeaders.Add("X-Seq-ApiKey", seqConfiguration.ApiKey);
|
||||
}
|
||||
public SeqHttpClient(SeqConfiguration seqConfiguration) : this(seqConfiguration, new HttpClientHandler()) { }
|
||||
|
||||
public async Task<HttpResponseMessage> SendAsync(HttpRequestMessage httpRequestMessage, CancellationToken cancellationToken)
|
||||
{
|
||||
return await _httpClient.SendAsync(httpRequestMessage, cancellationToken);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public class SeqLogger
|
||||
{
|
||||
private readonly SeqHttpClient _httpClient;
|
||||
|
|
@ -1,9 +1,10 @@
|
|||
using Autofac;
|
||||
using Core.Logging;
|
||||
using Core.Telemetry;
|
||||
|
||||
namespace Core.ModuleRegistry
|
||||
{
|
||||
public class SeqBackgroundServiceModule : Module
|
||||
public class SeqLoggingModule : Module
|
||||
{
|
||||
protected override void Load(ContainerBuilder builder)
|
||||
{
|
||||
|
|
@ -15,6 +16,13 @@ namespace Core.ModuleRegistry
|
|||
builder.RegisterType<SeqBackgroundService>()
|
||||
.As<Microsoft.Extensions.Hosting.IHostedService>()
|
||||
.SingleInstance();
|
||||
|
||||
builder.RegisterType<SeqHttpClient>()
|
||||
.As<SeqHttpClient>()
|
||||
.SingleInstance();
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -44,7 +44,7 @@ namespace Core.ModuleRegistry
|
|||
var tmc = Microsoft.ApplicationInsights.Extensibility.TelemetryConfiguration.CreateDefault();
|
||||
tmc.ConnectionString = TelemetryConfig.ConnectionString;
|
||||
tmc.TelemetryChannel.DeveloperMode = true;
|
||||
var channel = new Telemetry.DebugTelemetryChannel("C:\\logs\\telemetry.log");
|
||||
var channel = new Telemetry.SeqLoggingTelemetryChannel("C:\\logs\\telemetry.log");
|
||||
|
||||
tmc.TelemetryChannel = channel;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
namespace Core.CryptoService
|
||||
namespace Core.MultiKeyEncryption
|
||||
{
|
||||
internal class MasterKey
|
||||
{
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ using System.Security.Cryptography;
|
|||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Core.CryptoService
|
||||
namespace Core.MultiKeyEncryption
|
||||
{
|
||||
public class SecureConnectionString
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,101 +0,0 @@
|
|||
using Microsoft.ApplicationInsights;
|
||||
using Microsoft.ApplicationInsights.Channel;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Text;
|
||||
|
||||
namespace Core.Telemetry
|
||||
{
|
||||
public class SeqBackgroundService : BackgroundService
|
||||
{
|
||||
private readonly IMessageChannel<ITelemetry> _messageChannel;
|
||||
private readonly TelemetryClient _telemetryClient;
|
||||
private readonly HttpClient _httpClient;
|
||||
|
||||
public SeqBackgroundService(TelemetryClient telemetryClient,
|
||||
IMessageChannel<ITelemetry> messageChannel,
|
||||
HttpClient httpClient)
|
||||
{
|
||||
_telemetryClient = telemetryClient;
|
||||
_messageChannel = messageChannel;
|
||||
_httpClient = httpClient;
|
||||
|
||||
_httpClient = new HttpClient()
|
||||
{
|
||||
BaseAddress = new Uri("http://localhost:5341"),
|
||||
Timeout = TimeSpan.FromSeconds(30)
|
||||
};
|
||||
|
||||
_httpClient.DefaultRequestHeaders.Accept.Clear();
|
||||
_httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
|
||||
|
||||
|
||||
}
|
||||
|
||||
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
||||
{
|
||||
try
|
||||
{
|
||||
while (!stoppingToken.IsCancellationRequested)
|
||||
await foreach (var message in _messageChannel.Reader.ReadAllAsync(stoppingToken))
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
var eventTelemetry = message as Microsoft.ApplicationInsights.DataContracts.EventTelemetry;
|
||||
|
||||
var level = "Information";
|
||||
var seqEvent = new Dictionary<string, object>
|
||||
{
|
||||
{ "@t", DateTime.UtcNow.ToString("o") },
|
||||
{ "@mt", eventTelemetry.Name },
|
||||
{ "@l", level } // "Information", "Warning", "Error", etc.
|
||||
};
|
||||
|
||||
foreach (var prop in eventTelemetry.Context.GlobalProperties)
|
||||
{
|
||||
seqEvent.Add(prop.Key, prop.Value);
|
||||
}
|
||||
|
||||
var content = new StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(seqEvent), Encoding.UTF8, "application/vnd.serilog.clef");
|
||||
|
||||
var key = "4XhWFtY4jJ0NBgohBAFF"; ;
|
||||
//Gt8hS9ClGNfOCAdswDlW
|
||||
var requestMessage = new HttpRequestMessage(HttpMethod.Post, $"/ingest/clef?apiKey={key}");
|
||||
requestMessage.Content = content;
|
||||
|
||||
var response = await _httpClient.SendAsync(requestMessage, stoppingToken);
|
||||
|
||||
response.EnsureSuccessStatusCode();
|
||||
|
||||
//if (!response.IsSuccessStatusCode)
|
||||
//{
|
||||
// _telemetryClient.TrackTrace($"HTTP kald fejlede med status {response.StatusCode}", Microsoft.ApplicationInsights.DataContracts.SeverityLevel.Warning);
|
||||
// continue;
|
||||
//}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
//_telemetryClient.TrackException(ex); this is disabled for now, we need to think about the channel structure first
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (ex is not OperationCanceledException)
|
||||
{
|
||||
_telemetryClient.TrackException(ex);
|
||||
throw;
|
||||
}
|
||||
|
||||
_telemetryClient.TrackTrace("Service shutdown started");
|
||||
}
|
||||
}
|
||||
|
||||
public override async Task StopAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
_messageChannel.Dispose();
|
||||
await base.StopAsync(cancellationToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -3,13 +3,13 @@ using System.Net.Http.Headers;
|
|||
|
||||
namespace Core.Telemetry
|
||||
{
|
||||
public class DebugTelemetryChannel : InMemoryChannel, ITelemetryChannel
|
||||
public class SeqLoggingTelemetryChannel : InMemoryChannel, ITelemetryChannel
|
||||
{
|
||||
private readonly string _filePath;
|
||||
public ITelemetryChannel _defaultChannel;
|
||||
static HttpClient _client = new HttpClient();
|
||||
|
||||
static DebugTelemetryChannel()
|
||||
static SeqLoggingTelemetryChannel()
|
||||
{
|
||||
_client = new HttpClient()
|
||||
{
|
||||
|
|
@ -22,7 +22,7 @@ namespace Core.Telemetry
|
|||
}
|
||||
|
||||
|
||||
public DebugTelemetryChannel(string filePath)
|
||||
public SeqLoggingTelemetryChannel(string filePath)
|
||||
{
|
||||
_filePath = filePath;
|
||||
}
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
using Insight.Database;
|
||||
using System.Data;
|
||||
|
||||
namespace Database.Organizations
|
||||
namespace Database.Tenants
|
||||
{
|
||||
internal class InitializeOrganizationData
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,13 +1,8 @@
|
|||
using Core.Configurations.SmartConfig;
|
||||
using Core.Configurations;
|
||||
using Core.Configurations;
|
||||
using FluentAssertions;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Core.Configurations.JsonConfigProvider;
|
||||
using Autofac;
|
||||
using System.Data;
|
||||
using Insight.Database;
|
||||
using Npgsql;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Core.Configurations.SmartConfigProvider;
|
||||
|
||||
namespace Tests.ConfigurationTests
|
||||
{
|
||||
|
|
@ -25,7 +20,7 @@ namespace Tests.ConfigurationTests
|
|||
}") as JToken;
|
||||
|
||||
var builder = new ConfigurationBuilder()
|
||||
.AddJsonFile("appconfiguration.dev.json")
|
||||
.AddJsonFile("ConfigurationTests/appconfiguration.dev.json")
|
||||
.Build();
|
||||
|
||||
// Act
|
||||
|
|
|
|||
|
|
@ -1,7 +1,4 @@
|
|||
using Moq;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Tests;
|
||||
using Core.Configurations.SmartConfig;
|
||||
using Core.Configurations.Common;
|
||||
|
||||
namespace Tests.ConfigurationTests;
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
using Core.Configurations.SmartConfig;
|
||||
using Core.Configurations;
|
||||
using Core.Configurations;
|
||||
using FluentAssertions;
|
||||
using Core.Configurations.JsonConfigProvider;
|
||||
using Autofac;
|
||||
using System.Data;
|
||||
using Insight.Database;
|
||||
using Npgsql;
|
||||
using Core.Configurations.SmartConfigProvider;
|
||||
|
||||
namespace Tests.ConfigurationTests
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,17 +1,14 @@
|
|||
using Autofac;
|
||||
using System.Data;
|
||||
using Insight.Database;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Core.Telemetry;
|
||||
using Microsoft.ApplicationInsights;
|
||||
using Microsoft.ApplicationInsights.Channel;
|
||||
using Microsoft.ApplicationInsights.DataContracts;
|
||||
using Core.Logging;
|
||||
|
||||
namespace Tests
|
||||
namespace Tests.Logging
|
||||
{
|
||||
[TestClass]
|
||||
public class MessageChannelIntegrationTests : TestFixture
|
||||
public class SeqBackgroundServiceTest : TestFixture
|
||||
{
|
||||
private IMessageChannel<ITelemetry> _messageChannel;
|
||||
private SeqBackgroundService _service;
|
||||
|
|
@ -22,10 +19,17 @@ namespace Tests
|
|||
{
|
||||
_messageChannel = new MessageChannel();
|
||||
var telemetryClient = Container.Resolve<TelemetryClient>();
|
||||
var httpClient = new HttpClient(new TestMessageHandler());
|
||||
_service = new SeqBackgroundService(telemetryClient, _messageChannel, httpClient);
|
||||
|
||||
var config = new SeqConfiguration("http://localhost:5341", null, "MSTEST");
|
||||
|
||||
var httpClient = new SeqHttpClient(config);
|
||||
var logger = new SeqLogger(httpClient, Environment.MachineName, config);
|
||||
|
||||
|
||||
|
||||
_service = new SeqBackgroundService(telemetryClient, _messageChannel, logger);
|
||||
_cts = new CancellationTokenSource();
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task Messages_ShouldBeProcessedFromQueue()
|
||||
|
|
@ -1,8 +1,7 @@
|
|||
using Core.Telemetry;
|
||||
using Microsoft.ApplicationInsights.Channel;
|
||||
using Core.Logging;
|
||||
using Microsoft.ApplicationInsights.DataContracts;
|
||||
|
||||
namespace Tests.TelemetryLogging
|
||||
namespace Tests.Logging
|
||||
{
|
||||
[TestClass]
|
||||
public class SeqLoggerTests : TestFixture
|
||||
|
|
@ -34,8 +33,7 @@ namespace Tests.TelemetryLogging
|
|||
// Act
|
||||
await _logger.LogAsync(traceTelemetry);
|
||||
|
||||
// Du kan nu tjekke Seq med følgende query:
|
||||
// TestId = 'guid-værdi-her'
|
||||
|
||||
}
|
||||
[TestMethod]
|
||||
public async Task LogTraceTelemetry_SendsCorrectDataWithWarningLevel()
|
||||
|
|
@ -27,7 +27,10 @@
|
|||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="appconfiguration.dev.json">
|
||||
<None Update="xappconfiguration.dev.json">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="ConfigurationTests\appconfiguration.dev.json">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
|
|
|||
60
Tests/xappconfiguration.dev.json
Normal file
60
Tests/xappconfiguration.dev.json
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
{
|
||||
"AllowedHosts": "*",
|
||||
"ConnectionStrings": {
|
||||
"DefaultConnection": "Host=192.168.1.57;Port=5432;Database=ptmain;User Id=sathumper;Password=3911;"
|
||||
},
|
||||
"ApplicationInsights": {
|
||||
"ConnectionString": "InstrumentationKey=6d2e76ee-5343-4691-a5e3-81add43cb584;IngestionEndpoint=https://northeurope-0.in.applicationinsights.azure.com/"
|
||||
},
|
||||
"Authentication": "SHA256",
|
||||
"Feature": {
|
||||
"Enabled": true,
|
||||
"RolloutPercentage": 25,
|
||||
"AllowedUserGroups": [ "beta" ]
|
||||
},
|
||||
"AnotherSetting": {
|
||||
|
||||
"Thresholds": {
|
||||
"High": "123",
|
||||
"Low": "-1"
|
||||
},
|
||||
"Temperature": {
|
||||
|
||||
"Indoor": {
|
||||
"Max": { "Limit": 22 },
|
||||
"Min": { "Limit": 18 }
|
||||
},
|
||||
"Outdoor": {
|
||||
"Max": { "Limit": 12 },
|
||||
"Min": { "Limit": 9 }
|
||||
}
|
||||
}
|
||||
},
|
||||
"Serilog": {
|
||||
"MinimumLevel": {
|
||||
"Default": "Information",
|
||||
"Override": {
|
||||
"Microsoft": "Warning",
|
||||
"System": "Warning"
|
||||
}
|
||||
},
|
||||
"WriteTo": [
|
||||
{
|
||||
"Name": "Seq",
|
||||
"Args": {
|
||||
"serverUrl": "http://localhost:5341",
|
||||
"apiKey": ""
|
||||
}
|
||||
}
|
||||
],
|
||||
"Enrich": [
|
||||
"WithMachineName",
|
||||
"WithThreadId",
|
||||
"WithProcessId",
|
||||
"WithEnvironmentName"
|
||||
],
|
||||
"Properties": {
|
||||
"Application": "PlanTempus"
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue