forked from FarmMaps/FarmMapsApiClient
improved logging
This commit is contained in:
parent
beaf00a043
commit
fefd348930
@ -6,13 +6,15 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Google.Apis" Version="1.44.1" />
|
<PackageReference Include="Google.Apis" Version="1.44.1" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="3.1.2" />
|
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="3.1.14" />
|
||||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="3.1.2" />
|
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="3.1.14" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Http" Version="3.1.2" />
|
<PackageReference Include="Microsoft.Extensions.Http" Version="3.1.14" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="3.1.2" />
|
<PackageReference Include="Microsoft.Extensions.Logging" Version="3.1.14" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="3.1.2" />
|
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="3.1.14" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="3.1.2" />
|
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="3.1.14" />
|
||||||
<PackageReference Include="IdentityModel.OidcClient" Version="3.1.2" />
|
<PackageReference Include="IdentityModel.OidcClient" Version="3.1.2" />
|
||||||
|
<PackageReference Include="Serilog.AspNetCore" Version="4.1.0" />
|
||||||
|
<PackageReference Include="Serilog.Sinks.File" Version="4.1.0" />
|
||||||
<PackageReference Include="Winista.MimeDetect" Version="1.0.1" />
|
<PackageReference Include="Winista.MimeDetect" Version="1.0.1" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
using System;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using FarmmapsApi.HttpMessageHandlers;
|
using FarmmapsApi.HttpMessageHandlers;
|
||||||
@ -6,6 +7,10 @@ using FarmmapsApi.Services;
|
|||||||
using IdentityModel.Client;
|
using IdentityModel.Client;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Serilog;
|
||||||
|
using Serilog.Events;
|
||||||
|
using Serilog.Filters;
|
||||||
|
|
||||||
namespace FarmmapsApi
|
namespace FarmmapsApi
|
||||||
{
|
{
|
||||||
@ -37,10 +42,12 @@ namespace FarmmapsApi
|
|||||||
.AddHttpMessageHandler<FarmmapsAuthenticationHandler>()
|
.AddHttpMessageHandler<FarmmapsAuthenticationHandler>()
|
||||||
.Services;
|
.Services;
|
||||||
|
|
||||||
|
|
||||||
Configure(serviceCollection);
|
Configure(serviceCollection);
|
||||||
|
|
||||||
var serviceProvider = serviceCollection.BuildServiceProvider();
|
var serviceProvider = serviceCollection.BuildServiceProvider();
|
||||||
|
|
||||||
|
ConfigureLogger(serviceProvider);
|
||||||
|
|
||||||
await serviceProvider.GetService<FarmmapsApiService>().AuthenticateAsync();
|
await serviceProvider.GetService<FarmmapsApiService>().AuthenticateAsync();
|
||||||
// await serviceProvider.GetService<FarmmapsEventHub>().StartEventHub();
|
// await serviceProvider.GetService<FarmmapsEventHub>().StartEventHub();
|
||||||
|
|
||||||
@ -48,5 +55,20 @@ namespace FarmmapsApi
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected abstract void Configure(IServiceCollection serviceCollection);
|
protected abstract void Configure(IServiceCollection serviceCollection);
|
||||||
|
|
||||||
|
private static void ConfigureLogger(IServiceProvider serviceProvider)
|
||||||
|
{
|
||||||
|
var isService = Matching.FromSource("Microsoft");
|
||||||
|
|
||||||
|
Log.Logger = new LoggerConfiguration()
|
||||||
|
.MinimumLevel.Information()
|
||||||
|
.WriteTo.Logger(l => l.Filter.ByIncludingOnly(isService)
|
||||||
|
.WriteTo.Console(LogEventLevel.Warning))
|
||||||
|
.WriteTo.File(path: "Logs/log.log", rollingInterval: RollingInterval.Day)
|
||||||
|
.CreateLogger();
|
||||||
|
|
||||||
|
var loggerFactory = serviceProvider.GetRequiredService<ILoggerFactory>();
|
||||||
|
loggerFactory.AddSerilog();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -14,9 +14,7 @@ namespace FarmmapsVRApoten
|
|||||||
|
|
||||||
protected override void Configure(IServiceCollection serviceCollection)
|
protected override void Configure(IServiceCollection serviceCollection)
|
||||||
{
|
{
|
||||||
serviceCollection.AddLogging(opts => opts
|
serviceCollection.AddLogging()
|
||||||
.AddConsole()
|
|
||||||
.AddFilter("System.Net.Http", LogLevel.Warning))
|
|
||||||
.AddTransient<PotenService>();
|
.AddTransient<PotenService>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user