grundkæggende projekt struktur er på plads
This commit is contained in:
15
.idea/.gitignore
generated
vendored
Normal file
15
.idea/.gitignore
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Rider ignored files
|
||||
/contentModel.xml
|
||||
/projectSettingsUpdater.xml
|
||||
/.idea.SmartHouse.Services.iml
|
||||
/modules.xml
|
||||
# Ignored default folder with query files
|
||||
/queries/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
||||
4
.idea/encodings.xml
generated
Normal file
4
.idea/encodings.xml
generated
Normal file
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Encoding" addBOMForNewFiles="with BOM under Windows, with no BOM otherwise" />
|
||||
</project>
|
||||
8
.idea/indexLayout.xml
generated
Normal file
8
.idea/indexLayout.xml
generated
Normal file
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="UserContentModel">
|
||||
<attachedFolders />
|
||||
<explicitIncludes />
|
||||
<explicitExcludes />
|
||||
</component>
|
||||
</project>
|
||||
6
.idea/vcs.xml
generated
Normal file
6
.idea/vcs.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
15
SmartHouse.Services/.idea/.idea.SmartHouse.Services/.idea/.gitignore
generated
vendored
Normal file
15
SmartHouse.Services/.idea/.idea.SmartHouse.Services/.idea/.gitignore
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Rider ignored files
|
||||
/.idea.SmartHouse.Services.iml
|
||||
/contentModel.xml
|
||||
/modules.xml
|
||||
/projectSettingsUpdater.xml
|
||||
# Ignored default folder with query files
|
||||
/queries/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
||||
4
SmartHouse.Services/.idea/.idea.SmartHouse.Services/.idea/encodings.xml
generated
Normal file
4
SmartHouse.Services/.idea/.idea.SmartHouse.Services/.idea/encodings.xml
generated
Normal file
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Encoding" addBOMForNewFiles="with BOM under Windows, with no BOM otherwise" />
|
||||
</project>
|
||||
8
SmartHouse.Services/.idea/.idea.SmartHouse.Services/.idea/indexLayout.xml
generated
Normal file
8
SmartHouse.Services/.idea/.idea.SmartHouse.Services/.idea/indexLayout.xml
generated
Normal file
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="UserContentModel">
|
||||
<attachedFolders />
|
||||
<explicitIncludes />
|
||||
<explicitExcludes />
|
||||
</component>
|
||||
</project>
|
||||
6
SmartHouse.Services/.idea/.idea.SmartHouse.Services/.idea/vcs.xml
generated
Normal file
6
SmartHouse.Services/.idea/.idea.SmartHouse.Services/.idea/vcs.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
13
SmartHouse.Services/SmartHouse.Services.AppHost/AppHost.cs
Normal file
13
SmartHouse.Services/SmartHouse.Services.AppHost/AppHost.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
var builder = DistributedApplication.CreateBuilder(args);
|
||||
|
||||
builder.AddProject<Projects.SmartHouse_Services_Database>("smarthouse-services-database");
|
||||
|
||||
builder.AddProject<Projects.SmartHouse_Services_EVCharging>("smarthouse-services-evcharging");
|
||||
|
||||
builder.AddProject<Projects.SmartHouse_Services_HomeAssistent>("smarthouse-services-homeassistent");
|
||||
|
||||
builder.AddProject<Projects.SmartHouse_Services_Siemens>("smarthouse-services-siemens");
|
||||
|
||||
builder.AddProject<Projects.SmartHouse_Services_SunCast>("smarthouse-services-suncast");
|
||||
|
||||
builder.Build().Run();
|
||||
@@ -0,0 +1,31 @@
|
||||
{
|
||||
"$schema": "https://json.schemastore.org/launchsettings.json",
|
||||
"profiles": {
|
||||
"https": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": true,
|
||||
"applicationUrl": "https://localhost:17223;http://localhost:15039",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development",
|
||||
"DOTNET_ENVIRONMENT": "Development",
|
||||
"ASPIRE_DASHBOARD_OTLP_ENDPOINT_URL": "https://localhost:21227",
|
||||
"ASPIRE_DASHBOARD_MCP_ENDPOINT_URL": "https://localhost:23091",
|
||||
"ASPIRE_RESOURCE_SERVICE_ENDPOINT_URL": "https://localhost:22221"
|
||||
}
|
||||
},
|
||||
"http": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": true,
|
||||
"applicationUrl": "http://localhost:15039",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development",
|
||||
"DOTNET_ENVIRONMENT": "Development",
|
||||
"ASPIRE_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:19207",
|
||||
"ASPIRE_DASHBOARD_MCP_ENDPOINT_URL": "http://localhost:18000",
|
||||
"ASPIRE_RESOURCE_SERVICE_ENDPOINT_URL": "http://localhost:20178"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<Project Sdk="Aspire.AppHost.Sdk/13.1.0">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<UserSecretsId>90b46a44-f221-4903-b340-6fee7c8848f2</UserSecretsId>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\SmartHouse.Services.Database\SmartHouse.Services.Database.csproj" />
|
||||
<ProjectReference Include="..\SmartHouse.Services.EVCharging\SmartHouse.Services.EVCharging.csproj" />
|
||||
<ProjectReference Include="..\SmartHouse.Services.HomeAssistent\SmartHouse.Services.HomeAssistent.csproj" />
|
||||
<ProjectReference Include="..\SmartHouse.Services.Siemens\SmartHouse.Services.Siemens.csproj" />
|
||||
<ProjectReference Include="..\SmartHouse.Services.SunCast\SmartHouse.Services.SunCast.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning",
|
||||
"Aspire.Hosting.Dcp": "Warning"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
namespace SmartHouse.Services.Database;
|
||||
|
||||
public class Class1
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\SmartHouse.Services.ServiceDefaults\SmartHouse.Services.ServiceDefaults.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,9 @@
|
||||
using SmartHouse.Services.EVCharging;
|
||||
|
||||
var builder = Host.CreateApplicationBuilder(args);
|
||||
|
||||
builder.AddServiceDefaults();
|
||||
builder.Services.AddHostedService<Worker>();
|
||||
|
||||
var host = builder.Build();
|
||||
host.Run();
|
||||
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"$schema": "https://json.schemastore.org/launchsettings.json",
|
||||
"profiles": {
|
||||
"SmartHouse.Services.EVCharging": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"environmentVariables": {
|
||||
"DOTNET_ENVIRONMENT": "Development"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Worker">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<UserSecretsId>dotnet-SmartHouse.Services.EVCharging-8f24ed80-dad3-439c-b4e6-c654b00d1ae2</UserSecretsId>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="10.0.1"/>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\SmartHouse.Services.ServiceDefaults\SmartHouse.Services.ServiceDefaults.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
17
SmartHouse.Services/SmartHouse.Services.EVCharging/Worker.cs
Normal file
17
SmartHouse.Services/SmartHouse.Services.EVCharging/Worker.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
namespace SmartHouse.Services.EVCharging;
|
||||
|
||||
public class Worker(ILogger<Worker> logger) : BackgroundService
|
||||
{
|
||||
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
||||
{
|
||||
while (!stoppingToken.IsCancellationRequested)
|
||||
{
|
||||
if (logger.IsEnabled(LogLevel.Information))
|
||||
{
|
||||
logger.LogInformation("Worker running at: {time}", DateTimeOffset.Now);
|
||||
}
|
||||
|
||||
await Task.Delay(1000, stoppingToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.Hosting.Lifetime": "Information"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.Hosting.Lifetime": "Information"
|
||||
}
|
||||
}
|
||||
}
|
||||
27
SmartHouse.Services/SmartHouse.Services.Helper/IPerflog.cs
Normal file
27
SmartHouse.Services/SmartHouse.Services.Helper/IPerflog.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace SmartHouse.Services.Helper
|
||||
{
|
||||
public interface IPerfLog
|
||||
{
|
||||
void Info(string message, params object[] args);
|
||||
void Warn(string message, params object[] args);
|
||||
}
|
||||
|
||||
public sealed class PerfLog : IPerfLog
|
||||
{
|
||||
private readonly ILogger _log;
|
||||
|
||||
public PerfLog(ILoggerFactory factory)
|
||||
{
|
||||
// Matcher din rule: Performance.* -> perf.log
|
||||
_log = factory.CreateLogger("Performance.Worker");
|
||||
}
|
||||
|
||||
public void Info(string message, params object[] args)
|
||||
=> _log.LogInformation(message, args);
|
||||
|
||||
public void Warn(string message, params object[] args)
|
||||
=> _log.LogWarning(message, args);
|
||||
}
|
||||
}
|
||||
24
SmartHouse.Services/SmartHouse.Services.Helper/PerfLog.cs
Normal file
24
SmartHouse.Services/SmartHouse.Services.Helper/PerfLog.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
public interface IPerfLog
|
||||
{
|
||||
void Info(string message, params object[] args);
|
||||
void Warn(string message, params object[] args);
|
||||
}
|
||||
|
||||
public sealed class PerfLog : IPerfLog
|
||||
{
|
||||
private readonly ILogger _log;
|
||||
|
||||
public PerfLog(ILoggerFactory factory)
|
||||
{
|
||||
// Matcher rule: Performance.* → perf.log
|
||||
_log = factory.CreateLogger("Performance.Worker");
|
||||
}
|
||||
|
||||
public void Info(string message, params object[] args)
|
||||
=> _log.LogInformation(message, args);
|
||||
|
||||
public void Warn(string message, params object[] args)
|
||||
=> _log.LogWarning(message, args);
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="NLog" Version="6.0.7" />
|
||||
<PackageReference Include="NLog.Extensions.Hosting" Version="6.1.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,5 @@
|
||||
namespace SmartHouse.Services.HomeAssistent;
|
||||
|
||||
public class Class1
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\SmartHouse.Services.ServiceDefaults\SmartHouse.Services.ServiceDefaults.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,127 @@
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Diagnostics.HealthChecks;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.ServiceDiscovery;
|
||||
using OpenTelemetry;
|
||||
using OpenTelemetry.Metrics;
|
||||
using OpenTelemetry.Trace;
|
||||
|
||||
namespace Microsoft.Extensions.Hosting;
|
||||
|
||||
// Adds common Aspire services: service discovery, resilience, health checks, and OpenTelemetry.
|
||||
// This project should be referenced by each service project in your solution.
|
||||
// To learn more about using this project, see https://aka.ms/dotnet/aspire/service-defaults
|
||||
public static class Extensions
|
||||
{
|
||||
private const string HealthEndpointPath = "/health";
|
||||
private const string AlivenessEndpointPath = "/alive";
|
||||
|
||||
public static TBuilder AddServiceDefaults<TBuilder>(this TBuilder builder) where TBuilder : IHostApplicationBuilder
|
||||
{
|
||||
builder.ConfigureOpenTelemetry();
|
||||
|
||||
builder.AddDefaultHealthChecks();
|
||||
|
||||
builder.Services.AddServiceDiscovery();
|
||||
|
||||
builder.Services.ConfigureHttpClientDefaults(http =>
|
||||
{
|
||||
// Turn on resilience by default
|
||||
http.AddStandardResilienceHandler();
|
||||
|
||||
// Turn on service discovery by default
|
||||
http.AddServiceDiscovery();
|
||||
});
|
||||
|
||||
// Uncomment the following to restrict the allowed schemes for service discovery.
|
||||
// builder.Services.Configure<ServiceDiscoveryOptions>(options =>
|
||||
// {
|
||||
// options.AllowedSchemes = ["https"];
|
||||
// });
|
||||
|
||||
return builder;
|
||||
}
|
||||
|
||||
public static TBuilder ConfigureOpenTelemetry<TBuilder>(this TBuilder builder) where TBuilder : IHostApplicationBuilder
|
||||
{
|
||||
builder.Logging.AddOpenTelemetry(logging =>
|
||||
{
|
||||
logging.IncludeFormattedMessage = true;
|
||||
logging.IncludeScopes = true;
|
||||
});
|
||||
|
||||
builder.Services.AddOpenTelemetry()
|
||||
.WithMetrics(metrics =>
|
||||
{
|
||||
metrics.AddAspNetCoreInstrumentation()
|
||||
.AddHttpClientInstrumentation()
|
||||
.AddRuntimeInstrumentation();
|
||||
})
|
||||
.WithTracing(tracing =>
|
||||
{
|
||||
tracing.AddSource(builder.Environment.ApplicationName)
|
||||
.AddAspNetCoreInstrumentation(tracing =>
|
||||
// Exclude health check requests from tracing
|
||||
tracing.Filter = context =>
|
||||
!context.Request.Path.StartsWithSegments(HealthEndpointPath)
|
||||
&& !context.Request.Path.StartsWithSegments(AlivenessEndpointPath)
|
||||
)
|
||||
// Uncomment the following line to enable gRPC instrumentation (requires the OpenTelemetry.Instrumentation.GrpcNetClient package)
|
||||
//.AddGrpcClientInstrumentation()
|
||||
.AddHttpClientInstrumentation();
|
||||
});
|
||||
|
||||
builder.AddOpenTelemetryExporters();
|
||||
|
||||
return builder;
|
||||
}
|
||||
|
||||
private static TBuilder AddOpenTelemetryExporters<TBuilder>(this TBuilder builder) where TBuilder : IHostApplicationBuilder
|
||||
{
|
||||
var useOtlpExporter = !string.IsNullOrWhiteSpace(builder.Configuration["OTEL_EXPORTER_OTLP_ENDPOINT"]);
|
||||
|
||||
if (useOtlpExporter)
|
||||
{
|
||||
builder.Services.AddOpenTelemetry().UseOtlpExporter();
|
||||
}
|
||||
|
||||
// Uncomment the following lines to enable the Azure Monitor exporter (requires the Azure.Monitor.OpenTelemetry.AspNetCore package)
|
||||
//if (!string.IsNullOrEmpty(builder.Configuration["APPLICATIONINSIGHTS_CONNECTION_STRING"]))
|
||||
//{
|
||||
// builder.Services.AddOpenTelemetry()
|
||||
// .UseAzureMonitor();
|
||||
//}
|
||||
|
||||
return builder;
|
||||
}
|
||||
|
||||
public static TBuilder AddDefaultHealthChecks<TBuilder>(this TBuilder builder) where TBuilder : IHostApplicationBuilder
|
||||
{
|
||||
builder.Services.AddHealthChecks()
|
||||
// Add a default liveness check to ensure app is responsive
|
||||
.AddCheck("self", () => HealthCheckResult.Healthy(), ["live"]);
|
||||
|
||||
return builder;
|
||||
}
|
||||
|
||||
public static WebApplication MapDefaultEndpoints(this WebApplication app)
|
||||
{
|
||||
// Adding health checks endpoints to applications in non-development environments has security implications.
|
||||
// See https://aka.ms/dotnet/aspire/healthchecks for details before enabling these endpoints in non-development environments.
|
||||
if (app.Environment.IsDevelopment())
|
||||
{
|
||||
// All health checks must pass for app to be considered ready to accept traffic after starting
|
||||
app.MapHealthChecks(HealthEndpointPath);
|
||||
|
||||
// Only health checks tagged with the "live" tag must pass for app to be considered alive
|
||||
app.MapHealthChecks(AlivenessEndpointPath, new HealthCheckOptions
|
||||
{
|
||||
Predicate = r => r.Tags.Contains("live")
|
||||
});
|
||||
}
|
||||
|
||||
return app;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<IsAspireSharedProject>true</IsAspireSharedProject>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<FrameworkReference Include="Microsoft.AspNetCore.App"/>
|
||||
|
||||
<PackageReference Include="Microsoft.Extensions.Http.Resilience" Version="10.1.0"/>
|
||||
<PackageReference Include="Microsoft.Extensions.ServiceDiscovery" Version="10.1.0"/>
|
||||
<PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.14.0"/>
|
||||
<PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.14.0"/>
|
||||
<PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.14.0"/>
|
||||
<PackageReference Include="OpenTelemetry.Instrumentation.Http" Version="1.14.0"/>
|
||||
<PackageReference Include="OpenTelemetry.Instrumentation.Runtime" Version="1.14.0"/>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,90 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
autoReload="true"
|
||||
throwConfigExceptions="true"
|
||||
internalLogLevel="Warn"
|
||||
internalLogFile="logs/nlog-internal.log">
|
||||
|
||||
<!-- ========================= -->
|
||||
<!-- VARIABLES -->
|
||||
<!-- ========================= -->
|
||||
<variable name="appName" value="MyApp" />
|
||||
<variable name="environment" value="${aspnet-environment:whenEmpty=Production}" />
|
||||
|
||||
<variable name="logRoot" value="${basedir}/logs" />
|
||||
<variable name="year" value="${date:format=yyyy}" />
|
||||
<variable name="month" value="${date:format=MM}" />
|
||||
<variable name="day" value="${date:format=dd}" />
|
||||
|
||||
<!-- ========================= -->
|
||||
<!-- LAYOUTS -->
|
||||
<!-- ========================= -->
|
||||
<layout name="jsonLayout" xsi:type="JsonLayout" includeAllProperties="true">
|
||||
<attribute name="timestamp" layout="${date:format=o}" />
|
||||
<attribute name="level" layout="${level}" />
|
||||
<attribute name="logger" layout="${logger}" />
|
||||
<attribute name="message" layout="${message}" />
|
||||
<attribute name="exception" layout="${exception:format=ToString}" />
|
||||
<attribute name="correlationId" layout="${mdlc:item=CorrelationId}" />
|
||||
<attribute name="traceId" layout="${activityid}" />
|
||||
<attribute name="environment" layout="${environment}" />
|
||||
<attribute name="application" layout="${appName}" />
|
||||
</layout>
|
||||
|
||||
<!-- ========================= -->
|
||||
<!-- TARGETS -->
|
||||
<!-- ========================= -->
|
||||
<targets async="true">
|
||||
|
||||
<!-- Console (dev / Docker) -->
|
||||
<target xsi:type="Console"
|
||||
name="console"
|
||||
layout="${jsonLayout}" />
|
||||
|
||||
<!-- App log -->
|
||||
<target xsi:type="File"
|
||||
name="appFile"
|
||||
fileName="${logRoot}/${year}/${month}/${day}/app.log"
|
||||
layout="${jsonLayout}"
|
||||
concurrentWrites="true"
|
||||
keepFileOpen="false" />
|
||||
|
||||
<!-- Error log -->
|
||||
<target xsi:type="File"
|
||||
name="errorFile"
|
||||
fileName="${logRoot}/${year}/${month}/${day}/error.log"
|
||||
layout="${jsonLayout}"
|
||||
concurrentWrites="true"
|
||||
keepFileOpen="false" />
|
||||
|
||||
<!-- Performance log -->
|
||||
<target xsi:type="File"
|
||||
name="performanceFile"
|
||||
fileName="${logRoot}/${year}/${month}/${day}/perf.log"
|
||||
layout="${jsonLayout}"
|
||||
concurrentWrites="true"
|
||||
keepFileOpen="false" />
|
||||
|
||||
</targets>
|
||||
|
||||
<!-- ========================= -->
|
||||
<!-- RULES (MINIMAL) -->
|
||||
<!-- ========================= -->
|
||||
<rules>
|
||||
|
||||
<!-- Normal app flow -->
|
||||
<logger name="*" minlevel="Info" writeTo="console,appFile" />
|
||||
|
||||
<!-- Errors -->
|
||||
<logger name="*" minlevel="Error" writeTo="errorFile" />
|
||||
|
||||
<!-- Performance -->
|
||||
<logger name="Performance.*" minlevel="Info" writeTo="performanceFile" />
|
||||
|
||||
<!-- Reduce framework noise -->
|
||||
<logger name="Microsoft.*" maxlevel="Info" final="true" />
|
||||
<logger name="System.*" maxlevel="Warn" final="true" />
|
||||
|
||||
</rules>
|
||||
</nlog>
|
||||
|
||||
56
SmartHouse.Services/SmartHouse.Services.Siemens/Program.cs
Normal file
56
SmartHouse.Services/SmartHouse.Services.Siemens/Program.cs
Normal file
@@ -0,0 +1,56 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using NLog;
|
||||
using NLog.Extensions.Logging;
|
||||
using SmartHouse.Services.Siemens;
|
||||
|
||||
// NLog internal bootstrap logger (til hvis noget går galt før hosten er oppe)
|
||||
var bootstrapLogger = LogManager.Setup()
|
||||
.LoadConfigurationFromFile("NLog.config", optional: false)
|
||||
.GetCurrentClassLogger();
|
||||
|
||||
try
|
||||
{
|
||||
var builder = Host.CreateApplicationBuilder(args);
|
||||
|
||||
// Aspire service defaults (behold den)
|
||||
builder.AddServiceDefaults();
|
||||
|
||||
// 1) Fjern standard logging providers
|
||||
builder.Logging.ClearProviders();
|
||||
|
||||
// 2) (Valgfrit men anbefalet) Brug scopes (CorrelationId m.m.)
|
||||
builder.Logging.Configure(o =>
|
||||
{
|
||||
o.ActivityTrackingOptions =
|
||||
ActivityTrackingOptions.TraceId |
|
||||
ActivityTrackingOptions.SpanId |
|
||||
ActivityTrackingOptions.ParentId;
|
||||
});
|
||||
|
||||
// 3) Tilføj NLog som provider (læser din NLog.config)
|
||||
builder.Logging.AddNLog(new NLogProviderOptions
|
||||
{
|
||||
CaptureMessageTemplates = true,
|
||||
CaptureMessageProperties = true,
|
||||
IncludeScopes = true
|
||||
});
|
||||
|
||||
// Perf logger wrapper (DI-friendly, uden NLog i din domænekode)
|
||||
builder.Services.AddSingleton<IPerfLog, PerfLog>();
|
||||
|
||||
builder.Services.AddHostedService<Worker>();
|
||||
|
||||
var host = builder.Build();
|
||||
host.Run();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
bootstrapLogger.Error(ex, "Host terminated unexpectedly");
|
||||
throw;
|
||||
}
|
||||
finally
|
||||
{
|
||||
LogManager.Shutdown();
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"$schema": "https://json.schemastore.org/launchsettings.json",
|
||||
"profiles": {
|
||||
"SmartHouse.Services.Siemens": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"environmentVariables": {
|
||||
"DOTNET_ENVIRONMENT": "Development"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Worker">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<UserSecretsId>dotnet-SmartHouse.Services.Siemens-09de8319-5d84-47b2-8d81-a7eec428f8da</UserSecretsId>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="10.0.1" />
|
||||
<PackageReference Include="NLog" Version="6.0.7" />
|
||||
<PackageReference Include="NLog.Web.AspNetCore" Version="6.1.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\SmartHouse.Services.Helper\SmartHouse.Services.Helper.csproj" />
|
||||
<ProjectReference Include="..\SmartHouse.Services.ServiceDefaults\SmartHouse.Services.ServiceDefaults.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
17
SmartHouse.Services/SmartHouse.Services.Siemens/Worker.cs
Normal file
17
SmartHouse.Services/SmartHouse.Services.Siemens/Worker.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
namespace SmartHouse.Services.Siemens;
|
||||
|
||||
public class Worker(ILogger<Worker> logger) : BackgroundService
|
||||
{
|
||||
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
||||
{
|
||||
while (!stoppingToken.IsCancellationRequested)
|
||||
{
|
||||
if (logger.IsEnabled(LogLevel.Information))
|
||||
{
|
||||
logger.LogInformation("Worker running at: {time}", DateTimeOffset.Now);
|
||||
}
|
||||
|
||||
await Task.Delay(1000, stoppingToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.Hosting.Lifetime": "Information"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.Hosting.Lifetime": "Information"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
using SmartHouse.Services.SunCast;
|
||||
|
||||
var builder = Host.CreateApplicationBuilder(args);
|
||||
|
||||
builder.AddServiceDefaults();
|
||||
builder.Services.AddHostedService<Worker>();
|
||||
|
||||
var host = builder.Build();
|
||||
host.Run();
|
||||
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"$schema": "https://json.schemastore.org/launchsettings.json",
|
||||
"profiles": {
|
||||
"SmartHouse.Services.SunCast": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"environmentVariables": {
|
||||
"DOTNET_ENVIRONMENT": "Development"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Worker">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<UserSecretsId>dotnet-SmartHouse.Services.SunCast-5f688ae7-b693-4c9b-aa20-147fcd5c7b79</UserSecretsId>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="10.0.1"/>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\SmartHouse.Services.ServiceDefaults\SmartHouse.Services.ServiceDefaults.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
17
SmartHouse.Services/SmartHouse.Services.SunCast/Worker.cs
Normal file
17
SmartHouse.Services/SmartHouse.Services.SunCast/Worker.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
namespace SmartHouse.Services.SunCast;
|
||||
|
||||
public class Worker(ILogger<Worker> logger) : BackgroundService
|
||||
{
|
||||
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
||||
{
|
||||
while (!stoppingToken.IsCancellationRequested)
|
||||
{
|
||||
if (logger.IsEnabled(LogLevel.Information))
|
||||
{
|
||||
logger.LogInformation("Worker running at: {time}", DateTimeOffset.Now);
|
||||
}
|
||||
|
||||
await Task.Delay(1000, stoppingToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.Hosting.Lifetime": "Information"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.Hosting.Lifetime": "Information"
|
||||
}
|
||||
}
|
||||
}
|
||||
67
SmartHouse.Services/SmartHouse.Services.sln
Normal file
67
SmartHouse.Services/SmartHouse.Services.sln
Normal file
@@ -0,0 +1,67 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 18
|
||||
VisualStudioVersion = 18.1.11312.151 d18.0
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SmartHouse.Services.HomeAssistent", "SmartHouse.Services.HomeAssistent\SmartHouse.Services.HomeAssistent.csproj", "{5EE8D007-801D-4E7A-8F40-D89C7A61B5FD}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SmartHouse.Services.Database", "SmartHouse.Services.Database\SmartHouse.Services.Database.csproj", "{8430DCBF-8341-4F00-9017-035699B07FED}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SmartHouse.Services.Siemens", "SmartHouse.Services.Siemens\SmartHouse.Services.Siemens.csproj", "{158F4BB1-78CC-42FE-B712-5489F8626750}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SmartHouse.Services.SunCast", "SmartHouse.Services.SunCast\SmartHouse.Services.SunCast.csproj", "{02ADF617-BBE0-4681-ABAE-164A1BF43804}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SmartHouse.Services.EVCharging", "SmartHouse.Services.EVCharging\SmartHouse.Services.EVCharging.csproj", "{9C8B5C4D-0B34-4ACC-A5ED-8DE9705E3801}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SmartHouse.Services.AppHost", "SmartHouse.Services.AppHost\SmartHouse.Services.AppHost.csproj", "{966ADDAD-5DF9-4FC3-8ACC-D751EA633DF1}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SmartHouse.Services.ServiceDefaults", "SmartHouse.Services.ServiceDefaults\SmartHouse.Services.ServiceDefaults.csproj", "{980D4FF9-B1F4-4F5D-846F-38EE5E15CC0E}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SmartHouse.Services.Helper", "SmartHouse.Services.Helper\SmartHouse.Services.Helper.csproj", "{119F70AB-85D8-4715-A41D-AD8509CEC551}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{5EE8D007-801D-4E7A-8F40-D89C7A61B5FD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{5EE8D007-801D-4E7A-8F40-D89C7A61B5FD}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{5EE8D007-801D-4E7A-8F40-D89C7A61B5FD}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{5EE8D007-801D-4E7A-8F40-D89C7A61B5FD}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{8430DCBF-8341-4F00-9017-035699B07FED}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{8430DCBF-8341-4F00-9017-035699B07FED}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{8430DCBF-8341-4F00-9017-035699B07FED}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{8430DCBF-8341-4F00-9017-035699B07FED}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{158F4BB1-78CC-42FE-B712-5489F8626750}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{158F4BB1-78CC-42FE-B712-5489F8626750}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{158F4BB1-78CC-42FE-B712-5489F8626750}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{158F4BB1-78CC-42FE-B712-5489F8626750}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{02ADF617-BBE0-4681-ABAE-164A1BF43804}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{02ADF617-BBE0-4681-ABAE-164A1BF43804}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{02ADF617-BBE0-4681-ABAE-164A1BF43804}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{02ADF617-BBE0-4681-ABAE-164A1BF43804}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{9C8B5C4D-0B34-4ACC-A5ED-8DE9705E3801}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{9C8B5C4D-0B34-4ACC-A5ED-8DE9705E3801}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{9C8B5C4D-0B34-4ACC-A5ED-8DE9705E3801}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{9C8B5C4D-0B34-4ACC-A5ED-8DE9705E3801}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{966ADDAD-5DF9-4FC3-8ACC-D751EA633DF1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{966ADDAD-5DF9-4FC3-8ACC-D751EA633DF1}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{966ADDAD-5DF9-4FC3-8ACC-D751EA633DF1}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{966ADDAD-5DF9-4FC3-8ACC-D751EA633DF1}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{980D4FF9-B1F4-4F5D-846F-38EE5E15CC0E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{980D4FF9-B1F4-4F5D-846F-38EE5E15CC0E}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{980D4FF9-B1F4-4F5D-846F-38EE5E15CC0E}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{980D4FF9-B1F4-4F5D-846F-38EE5E15CC0E}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{119F70AB-85D8-4715-A41D-AD8509CEC551}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{119F70AB-85D8-4715-A41D-AD8509CEC551}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{119F70AB-85D8-4715-A41D-AD8509CEC551}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{119F70AB-85D8-4715-A41D-AD8509CEC551}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {6F06BFFD-CD82-4F8C-AB9B-D63797D89B84}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
Reference in New Issue
Block a user