diff --git a/Directory.Build.pre.targets b/Directory.Build.initial.targets similarity index 100% rename from Directory.Build.pre.targets rename to Directory.Build.initial.targets diff --git a/Directory.Build.targets b/Directory.Build.targets index d6deacf..a24fb0f 100644 --- a/Directory.Build.targets +++ b/Directory.Build.targets @@ -2,7 +2,7 @@ - + 9.*-* @@ -34,6 +34,8 @@ 8.* $(FrameworkVersion) + 6.3.1 + 6.4.* 6.* diff --git a/NetLah.Serilog.sln b/NetLah.Serilog.sln index 9961799..f777c33 100644 --- a/NetLah.Serilog.sln +++ b/NetLah.Serilog.sln @@ -8,18 +8,17 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{2D57 samples\Directory.Build.props = samples\Directory.Build.props EndProjectSection EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples7", "samples7", "{29D9BC81-0F7D-4046-856D-30172EA3CD67}" -EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{43ECBF11-5D83-49DE-BE0A-1A8B4E254A3B}" ProjectSection(SolutionItems) = preProject .editorconfig = .editorconfig .azure\pipelines\azure-pipelines.yml = .azure\pipelines\azure-pipelines.yml Common.props = Common.props DevNotes.md = DevNotes.md + Directory.Build.initial.targets = Directory.Build.initial.targets Directory.Build.override.targets = Directory.Build.override.targets - Directory.Build.pre.targets = Directory.Build.pre.targets Directory.Build.props = Directory.Build.props Directory.Build.targets = Directory.Build.targets + .github\workflows\dotnet-core.yml = .github\workflows\dotnet-core.yml README.md = README.md EndProjectSection EndProject @@ -52,9 +51,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SampleWorkerService", "samp EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NetLah.Extensions.Logging.Reference.Test", "test\NetLah.Extensions.Logging.Reference.Test\NetLah.Extensions.Logging.Reference.Test.csproj", "{759D3749-BAB0-4B21-AEAF-B5522C54B02A}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SampleConsoleApp7", "sample7\SampleConsoleApp7\SampleConsoleApp7.csproj", "{AAC70FC1-FD5B-401C-885E-F90CFC63D008}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SampleConsoleAppDI7", "sample7\SampleConsoleAppDI7\SampleConsoleAppDI7.csproj", "{84839BA7-DE35-4660-9555-D73F5AB07C7D}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SampleWebApi5", "samples\SampleWebApi5\SampleWebApi5.csproj", "{667FF67C-C861-43EE-B1E4-A24A083C4E8A}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -98,14 +95,10 @@ Global {759D3749-BAB0-4B21-AEAF-B5522C54B02A}.Debug|Any CPU.Build.0 = Debug|Any CPU {759D3749-BAB0-4B21-AEAF-B5522C54B02A}.Release|Any CPU.ActiveCfg = Release|Any CPU {759D3749-BAB0-4B21-AEAF-B5522C54B02A}.Release|Any CPU.Build.0 = Release|Any CPU - {AAC70FC1-FD5B-401C-885E-F90CFC63D008}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {AAC70FC1-FD5B-401C-885E-F90CFC63D008}.Debug|Any CPU.Build.0 = Debug|Any CPU - {AAC70FC1-FD5B-401C-885E-F90CFC63D008}.Release|Any CPU.ActiveCfg = Release|Any CPU - {AAC70FC1-FD5B-401C-885E-F90CFC63D008}.Release|Any CPU.Build.0 = Release|Any CPU - {84839BA7-DE35-4660-9555-D73F5AB07C7D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {84839BA7-DE35-4660-9555-D73F5AB07C7D}.Debug|Any CPU.Build.0 = Debug|Any CPU - {84839BA7-DE35-4660-9555-D73F5AB07C7D}.Release|Any CPU.ActiveCfg = Release|Any CPU - {84839BA7-DE35-4660-9555-D73F5AB07C7D}.Release|Any CPU.Build.0 = Release|Any CPU + {667FF67C-C861-43EE-B1E4-A24A083C4E8A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {667FF67C-C861-43EE-B1E4-A24A083C4E8A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {667FF67C-C861-43EE-B1E4-A24A083C4E8A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {667FF67C-C861-43EE-B1E4-A24A083C4E8A}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -120,8 +113,7 @@ Global {068A9B74-0D51-4C99-B929-E64243BF5F52} = {2D574F61-A8A3-409A-9041-171544CAA477} {1F7A9ED1-EC3A-4404-A426-50A4B2865750} = {2D574F61-A8A3-409A-9041-171544CAA477} {759D3749-BAB0-4B21-AEAF-B5522C54B02A} = {7ECD3F17-05A7-4A7C-9A95-C8C75D73EA49} - {AAC70FC1-FD5B-401C-885E-F90CFC63D008} = {29D9BC81-0F7D-4046-856D-30172EA3CD67} - {84839BA7-DE35-4660-9555-D73F5AB07C7D} = {29D9BC81-0F7D-4046-856D-30172EA3CD67} + {667FF67C-C861-43EE-B1E4-A24A083C4E8A} = {2D574F61-A8A3-409A-9041-171544CAA477} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {756FF949-EAAC-4047-89DB-EB559A767C6C} diff --git a/sample7/Directory.Build.props b/sample7/Directory.Build.props deleted file mode 100644 index 2891b7e..0000000 --- a/sample7/Directory.Build.props +++ /dev/null @@ -1,10 +0,0 @@ - - - - false - true - - - - - diff --git a/sample7/SampleConsoleApp7/Properties/launchSettings.json b/sample7/SampleConsoleApp7/Properties/launchSettings.json deleted file mode 100644 index b892cfc..0000000 --- a/sample7/SampleConsoleApp7/Properties/launchSettings.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "profiles": { - "SampleConsoleApp7": { - "commandName": "Project", - "workingDirectory": ".", - "environmentVariables": { - "DOTNET_ENVIRONMENT": "Development" - } - } - } -} \ No newline at end of file diff --git a/sample7/SampleConsoleApp7/SampleConsoleApp7.csproj b/sample7/SampleConsoleApp7/SampleConsoleApp7.csproj deleted file mode 100644 index c41d1ce..0000000 --- a/sample7/SampleConsoleApp7/SampleConsoleApp7.csproj +++ /dev/null @@ -1,61 +0,0 @@ - - - - Exe - net7.0;net6.0;net5.0;netcoreapp3.1 - false - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/sample7/SampleConsoleAppDI7/Properties/launchSettings.json b/sample7/SampleConsoleAppDI7/Properties/launchSettings.json deleted file mode 100644 index efcc1b4..0000000 --- a/sample7/SampleConsoleAppDI7/Properties/launchSettings.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "profiles": { - "SampleConsoleAppDI7": { - "commandName": "Project", - "workingDirectory": ".", - "environmentVariables": { - "DOTNET_ENVIRONMENT": "Development" - } - } - } -} \ No newline at end of file diff --git a/sample7/SampleConsoleAppDI7/SampleConsoleAppDI7.csproj b/sample7/SampleConsoleAppDI7/SampleConsoleAppDI7.csproj deleted file mode 100644 index 5909af3..0000000 --- a/sample7/SampleConsoleAppDI7/SampleConsoleAppDI7.csproj +++ /dev/null @@ -1,63 +0,0 @@ - - - - Exe - net7.0;net6.0;net5.0;netcoreapp3.1 - false - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/samples/SampleWebApi5/Controllers/WeatherForecastController.cs b/samples/SampleWebApi5/Controllers/WeatherForecastController.cs new file mode 100644 index 0000000..54c6917 --- /dev/null +++ b/samples/SampleWebApi5/Controllers/WeatherForecastController.cs @@ -0,0 +1,37 @@ +using Microsoft.AspNetCore.Mvc; + +namespace SampleWebApi.Controllers; + +[ApiController] +[Route("[controller]")] +public class WeatherForecastController : ControllerBase +{ + private static readonly string[] Summaries = new[] + { + "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" + }; + + private readonly ILogger _logger; + + public WeatherForecastController(ILogger logger) + { + _logger = logger; + } + + [HttpGet] + public IEnumerable Get() + { + var rng = new Random(); + var result = Enumerable.Range(1, 5).Select(index => new WeatherForecast + { + Date = DateTime.Now.AddDays(index), + TemperatureC = rng.Next(-20, 55), + Summary = Summaries[rng.Next(Summaries.Length)] + }) + .ToArray(); + + _logger.LogInformation("Returns {name}", result.Select(w => w.Summary)); + + return result; + } +} diff --git a/samples/SampleWebApi5/Program.cs b/samples/SampleWebApi5/Program.cs new file mode 100644 index 0000000..7acb710 --- /dev/null +++ b/samples/SampleWebApi5/Program.cs @@ -0,0 +1,42 @@ +using NetLah.Diagnostics; +using NetLah.Extensions.Logging; + +namespace SampleWebApi; + +internal class Program +{ + public static void Main(string[] args) + { + ApplicationInfo.Initialize(null); + AppLog.InitLogger(); + try + { + AppLog.Logger.LogInformation("Application configure..."); // write log console only + + CreateHostBuilder(args).Build().Run(); + } + catch (Exception ex) + { + AppLog.Logger.LogCritical(ex, "Host terminated unexpectedly"); + } + finally + { + Serilog.Log.CloseAndFlush(); + } + } + + public static IHostBuilder CreateHostBuilder(string[] args) => + Host.CreateDefaultBuilder(args) + .UseSerilog2(logger => + { + if (ApplicationInfo.Instance is { } appInfo) + { + logger.LogInformation("Application initializing... AppTitle:{appTitle}; Version:{appVersion} BuildTime:{appBuildTime}; Framework:{frameworkName}", + appInfo.Title, appInfo.InformationalVersion, appInfo.BuildTimestampLocal, appInfo.FrameworkName); + } + }) // write log to sinks + .ConfigureWebHostDefaults(webBuilder => + { + webBuilder.UseStartup(); + }); +} diff --git a/samples/SampleWebApi5/Properties/launchSettings.json b/samples/SampleWebApi5/Properties/launchSettings.json new file mode 100644 index 0000000..380a32b --- /dev/null +++ b/samples/SampleWebApi5/Properties/launchSettings.json @@ -0,0 +1,31 @@ +{ + "$schema": "http://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:38544", + "sslPort": 44357 + } + }, + "profiles": { + "SampleWebApi5": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": false, + "launchUrl": "swagger", + "applicationUrl": "https://localhost:5001;http://localhost:5000", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/samples/SampleWebApi5/SampleWebApi5.csproj b/samples/SampleWebApi5/SampleWebApi5.csproj new file mode 100644 index 0000000..395a370 --- /dev/null +++ b/samples/SampleWebApi5/SampleWebApi5.csproj @@ -0,0 +1,39 @@ + + + + net8.0;net7.0;net6.0;net5.0;netcoreapp3.1 + false + netlah-serilog-31ba4057fe93 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/samples/SampleWebApi5/Startup.cs b/samples/SampleWebApi5/Startup.cs new file mode 100644 index 0000000..efafaff --- /dev/null +++ b/samples/SampleWebApi5/Startup.cs @@ -0,0 +1,56 @@ +using Microsoft.OpenApi.Models; +using NetLah.Extensions.Logging; + +namespace SampleWebApi; + +public class Startup +{ + public Startup(IConfiguration configuration) + { + AppLog.Logger.LogInformation("Startup constructor"); // write log to sinks + Configuration = configuration; + } + + public IConfiguration Configuration { get; } + + // This method gets called by the runtime. Use this method to add services to the container. + public void ConfigureServices(IServiceCollection services) + { + var logger = AppLog.Logger; + logger.LogInformation("ConfigureServices..."); // write log to sinks + + services.AddControllers(); + services.AddSwaggerGen(c => + { + c.SwaggerDoc("v1", new OpenApiInfo { Title = "SampleWebApi", Version = "v1" }); + }); + } + + // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. + public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILogger logger) + { + var logger1 = AppLog.Logger; + logger1.LogInformation("ConfigureApplication..."); // write log to sinks + logger.LogInformation("[Startup] ConfigureApplication..."); // write log to sinks + + if (env.IsDevelopment()) + { + app.UseDeveloperExceptionPage(); + app.UseSwagger(); + app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "SampleWebApi v1")); + } + + app.UseSerilogRequestLoggingLevel(); + + app.UseHttpsRedirection(); + + app.UseRouting(); + + app.UseAuthorization(); + + app.UseEndpoints(endpoints => + { + endpoints.MapControllers(); + }); + } +} diff --git a/samples/SampleWebApi5/WeatherForecast.cs b/samples/SampleWebApi5/WeatherForecast.cs new file mode 100644 index 0000000..aba6ae2 --- /dev/null +++ b/samples/SampleWebApi5/WeatherForecast.cs @@ -0,0 +1,12 @@ +namespace SampleWebApi; + +public class WeatherForecast +{ + public DateTime Date { get; set; } + + public int TemperatureC { get; set; } + + public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); + + public string? Summary { get; set; } +} diff --git a/samples/SampleWebApi5/appsettings.Development.json b/samples/SampleWebApi5/appsettings.Development.json new file mode 100644 index 0000000..50448eb --- /dev/null +++ b/samples/SampleWebApi5/appsettings.Development.json @@ -0,0 +1,27 @@ +{ + "Serilog": { + "Using:1": "Serilog.Sinks.Debug", + "Using:2": "Serilog.Sinks.File", + "MinimumLevel": { + "Default": "Debug", + "Override": { + "App": "Debug" + } + }, + "WriteTo:1": { "Name": "Debug" }, + "WriteTo:2": { + "Name": "File", + "Args": { + "path": "Logs/sample-.log", + "rollingInterval": "Day" + } + } + //"WriteTo:3": { + // "Name": "Seq", + // "Args": { + // "serverUrl": "https://seq", + // "apiKey": "ZrV42..." + // } + //}, + } +} diff --git a/samples/SampleWebApi5/appsettings.json b/samples/SampleWebApi5/appsettings.json new file mode 100644 index 0000000..85d2be7 --- /dev/null +++ b/samples/SampleWebApi5/appsettings.json @@ -0,0 +1,37 @@ +{ + "AllowedHosts": "*", + "Serilog": { + "Using": [ + "Serilog.Sinks.Console" + ], + "MinimumLevel": { + "Default": "Information", + "Override": { + "App": "Information", + "System": "Warning", + "Microsoft": "Warning", + "Microsoft.AspNetCore.Authentication": "Information", + "Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker": "Error", + "Microsoft.Hosting.Lifetime": "Information" + } + }, + "WriteTo:0": { "Name": "Console" }, + "Enrich": [ "FromLogContext", "WithMachineName" ], + "Destructure": [ + { + "Name": "ToMaximumDepth", + "Args": { "maximumDestructuringDepth": 4 } + }, + { + "Name": "ToMaximumStringLength", + "Args": { "maximumStringLength": 100 } + }, + { + "Name": "ToMaximumCollectionCount", + "Args": { "maximumCollectionCount": 10 } + } + ], + "Properties": { + } + } +} diff --git a/src/Directory.Build.targets b/src/Directory.Build.targets index eefe66c..9bfda8d 100644 --- a/src/Directory.Build.targets +++ b/src/Directory.Build.targets @@ -2,7 +2,7 @@ - + 9.*-* diff --git a/src/NetLah.Extensions.Logging.Serilog.AspNetCore/NetLah.Extensions.Logging.Serilog.AspNetCore.csproj b/src/NetLah.Extensions.Logging.Serilog.AspNetCore/NetLah.Extensions.Logging.Serilog.AspNetCore.csproj index 1eadbf0..2680155 100644 --- a/src/NetLah.Extensions.Logging.Serilog.AspNetCore/NetLah.Extensions.Logging.Serilog.AspNetCore.csproj +++ b/src/NetLah.Extensions.Logging.Serilog.AspNetCore/NetLah.Extensions.Logging.Serilog.AspNetCore.csproj @@ -3,7 +3,7 @@ NetLah.Extensions.Logging.Serilog.AspNetCore logging;serilog;dotnet;netcore;aspnetcore;worker;worker-service - net8.0;net7.0;net6.0;netcoreapp3.1 + net8.0;net7.0;net6.0;net5.0;netcoreapp3.1 Initializing Serilog and wrapping Serilog to `Microsoft.Extensions.Logging.ILogger` for ASP.NETCore and WorkerService true ../../NetLah.snk