diff --git a/README.md b/README.md index 9358681..f6e722b 100644 --- a/README.md +++ b/README.md @@ -102,3 +102,9 @@ logBuilder.AddTelegram(options, CreateFormatter); ``` For using custom message formatter delegate Func should be passed to extensions method AddTelegram. Delegate should be used because formatter needs to know which category is used for rendering the message. + + +## Get a digital subscription for project news +[Subscribe](https://twitter.com/intent/user?screen_name=andrew_gubskiy) to my Twitter to keep up-to-date with project news and receive announcements. + +[![Twitter URL](https://img.shields.io/twitter/url/https/twitter.com/andrew_gubskiy.svg?style=social&label=Follow%20%40andrew_gubskiy)](https://twitter.com/andrew_gubskiy) \ No newline at end of file diff --git a/X.Extensions.Logging.Telegram.sln b/X.Extensions.Logging.Telegram.sln index dc9412e..feefc7e 100644 --- a/X.Extensions.Logging.Telegram.sln +++ b/X.Extensions.Logging.Telegram.sln @@ -10,11 +10,9 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "X.Extensions.Logging.Telegr EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "examples", "examples", "{FE4C92EB-3AE0-4FC2-B2C5-5C94820B1763}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebApp", "examples\WebApp\WebApp.csproj", "{0D0DB3AB-7168-40AD-9844-E287D32C9F0A}" -EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleApp", "examples\ConsoleApp\ConsoleApp.csproj", "{0CB25DBB-1659-4BE3-AE19-189ED5808E74}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebApp.NextVersion", "examples\WebApp.NextVersion\WebApp.NextVersion.csproj", "{AED236EF-E9D0-4820-8CB7-D35F8EE6AB6F}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebApp", "examples\WebApp\WebApp.csproj", "{AED236EF-E9D0-4820-8CB7-D35F8EE6AB6F}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -30,10 +28,6 @@ Global {8E60254D-72D7-4E6E-8592-E12F01FFBF0C}.Debug|Any CPU.Build.0 = Debug|Any CPU {8E60254D-72D7-4E6E-8592-E12F01FFBF0C}.Release|Any CPU.ActiveCfg = Release|Any CPU {8E60254D-72D7-4E6E-8592-E12F01FFBF0C}.Release|Any CPU.Build.0 = Release|Any CPU - {0D0DB3AB-7168-40AD-9844-E287D32C9F0A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {0D0DB3AB-7168-40AD-9844-E287D32C9F0A}.Debug|Any CPU.Build.0 = Debug|Any CPU - {0D0DB3AB-7168-40AD-9844-E287D32C9F0A}.Release|Any CPU.ActiveCfg = Release|Any CPU - {0D0DB3AB-7168-40AD-9844-E287D32C9F0A}.Release|Any CPU.Build.0 = Release|Any CPU {0CB25DBB-1659-4BE3-AE19-189ED5808E74}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {0CB25DBB-1659-4BE3-AE19-189ED5808E74}.Debug|Any CPU.Build.0 = Debug|Any CPU {0CB25DBB-1659-4BE3-AE19-189ED5808E74}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -46,7 +40,6 @@ Global GlobalSection(NestedProjects) = preSolution {0E1C0807-2482-4007-B0E0-F87A3A9A2898} = {D7219AE6-E36B-4CE1-9581-B341751BA4EB} {8E60254D-72D7-4E6E-8592-E12F01FFBF0C} = {4EE5DDEB-64BD-4BA7-95E6-1C3E82DF1671} - {0D0DB3AB-7168-40AD-9844-E287D32C9F0A} = {FE4C92EB-3AE0-4FC2-B2C5-5C94820B1763} {0CB25DBB-1659-4BE3-AE19-189ED5808E74} = {FE4C92EB-3AE0-4FC2-B2C5-5C94820B1763} {AED236EF-E9D0-4820-8CB7-D35F8EE6AB6F} = {FE4C92EB-3AE0-4FC2-B2C5-5C94820B1763} EndGlobalSection diff --git a/examples/ConsoleApp/ConsoleApp.csproj b/examples/ConsoleApp/ConsoleApp.csproj index 2496636..547713f 100644 --- a/examples/ConsoleApp/ConsoleApp.csproj +++ b/examples/ConsoleApp/ConsoleApp.csproj @@ -3,7 +3,7 @@ Exe net6.0 - 10 + default diff --git a/examples/WebApp.NextVersion/Controllers/WeatherForecastController.cs b/examples/WebApp.NextVersion/Controllers/WeatherForecastController.cs deleted file mode 100644 index c337741..0000000 --- a/examples/WebApp.NextVersion/Controllers/WeatherForecastController.cs +++ /dev/null @@ -1,42 +0,0 @@ -using Microsoft.AspNetCore.Mvc; - -namespace WebApp.NextVersion.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(Name = "GetWeatherForecast")] - public IEnumerable Get() - { - var rng = new Random(); - var temperatureC = rng.Next(-20, 55); - - _logger.LogTrace($"Trace Temperature: {temperatureC}"); - _logger.LogDebug($"Debug Temperature: {temperatureC}"); - _logger.LogInformation($"Information Temperature: {temperatureC}"); - _logger.LogWarning($"Warning Temperature: {temperatureC}"); - _logger.LogError($"Error Temperature: {temperatureC}"); - _logger.LogCritical($"Critical Temperature: {temperatureC}"); - - return Enumerable.Range(1, 5).Select(index => new WeatherForecast - { - Date = DateTime.Now.AddDays(index), - TemperatureC = temperatureC, - Summary = Summaries[rng.Next(Summaries.Length)] - }) - .ToArray(); - } -} \ No newline at end of file diff --git a/examples/WebApp.NextVersion/Program.cs b/examples/WebApp.NextVersion/Program.cs deleted file mode 100644 index 8b61615..0000000 --- a/examples/WebApp.NextVersion/Program.cs +++ /dev/null @@ -1,31 +0,0 @@ -using X.Extensions.Logging.Telegram; - -var builder = WebApplication.CreateBuilder(args); - -// Add services to the container. - -builder.Services.AddControllers(); -// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle -builder.Services.AddEndpointsApiExplorer(); -builder.Services.AddSwaggerGen(); - -builder.Logging.ClearProviders(); -builder.Logging.AddConsole(); -builder.Logging.AddTelegram(builder.Configuration); - -var app = builder.Build(); - -// Configure the HTTP request pipeline. -if (app.Environment.IsDevelopment()) -{ - app.UseSwagger(); - app.UseSwaggerUI(); -} - -app.UseHttpsRedirection(); - -app.UseAuthorization(); - -app.MapControllers(); - -app.Run(); \ No newline at end of file diff --git a/examples/WebApp.NextVersion/Properties/launchSettings.json b/examples/WebApp.NextVersion/Properties/launchSettings.json deleted file mode 100644 index 942149f..0000000 --- a/examples/WebApp.NextVersion/Properties/launchSettings.json +++ /dev/null @@ -1,31 +0,0 @@ -{ - "$schema": "https://json.schemastore.org/launchsettings.json", - "iisSettings": { - "windowsAuthentication": false, - "anonymousAuthentication": true, - "iisExpress": { - "applicationUrl": "http://localhost:24153", - "sslPort": 44367 - } - }, - "profiles": { - "WebApp.NextVersion": { - "commandName": "Project", - "dotnetRunMessages": true, - "launchBrowser": true, - "launchUrl": "swagger", - "applicationUrl": "https://localhost:7065;http://localhost:5130", - "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" - } - }, - "IIS Express": { - "commandName": "IISExpress", - "launchBrowser": true, - "launchUrl": "swagger", - "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" - } - } - } -} diff --git a/examples/WebApp.NextVersion/WeatherForecast.cs b/examples/WebApp.NextVersion/WeatherForecast.cs deleted file mode 100644 index 2b9818c..0000000 --- a/examples/WebApp.NextVersion/WeatherForecast.cs +++ /dev/null @@ -1,12 +0,0 @@ -namespace WebApp.NextVersion; - -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; } -} \ No newline at end of file diff --git a/examples/WebApp.NextVersion/WebApp.NextVersion.csproj b/examples/WebApp.NextVersion/WebApp.NextVersion.csproj deleted file mode 100644 index 9f5a746..0000000 --- a/examples/WebApp.NextVersion/WebApp.NextVersion.csproj +++ /dev/null @@ -1,17 +0,0 @@ - - - - net6.0 - enable - enable - - - - - - - - - - - diff --git a/examples/WebApp.NextVersion/appsettings.Development.json b/examples/WebApp.NextVersion/appsettings.Development.json deleted file mode 100644 index 0c208ae..0000000 --- a/examples/WebApp.NextVersion/appsettings.Development.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "Logging": { - "LogLevel": { - "Default": "Information", - "Microsoft.AspNetCore": "Warning" - } - } -} diff --git a/examples/WebApp.NextVersion/appsettings.json b/examples/WebApp.NextVersion/appsettings.json deleted file mode 100644 index 1d32d4a..0000000 --- a/examples/WebApp.NextVersion/appsettings.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "Logging": { - "LogLevel": { - "Default": "Information", - "Microsoft.AspNetCore": "Warning" - }, - "Telegram": { - "LogLevel": { - "Default": "Error" - }, - "AccessToken": "1234567890:AAAaaAAaa_AaAAaa-AAaAAAaAAaAaAaAAAA", - "ChatId": "-0000000000000", - "UseEmoji": "true", - "Source": "WebApp.NextVersion" - } - }, - "AllowedHosts": "*" -} diff --git a/examples/WebApp/Controllers/WeatherForecastController.cs b/examples/WebApp/Controllers/WeatherForecastController.cs index c445745..8cf715f 100644 --- a/examples/WebApp/Controllers/WeatherForecastController.cs +++ b/examples/WebApp/Controllers/WeatherForecastController.cs @@ -1,50 +1,42 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; -using Microsoft.Extensions.Logging; -namespace WebApp.Controllers +namespace WebApp.Controllers; + +[ApiController] +[Route("[controller]")] +public class WeatherForecastController : ControllerBase { - [ApiController] - [Route("[controller]")] - public class WeatherForecastController : ControllerBase + private static readonly string[] Summaries = new[] { - private static readonly string[] Summaries = new[] - { - "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" - }; + "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" + }; - private readonly ILogger _logger; + private readonly ILogger _logger; - public WeatherForecastController(ILogger logger) - { - _logger = logger; - - _logger.LogWarning("WeatherForecastController created"); - } + public WeatherForecastController(ILogger logger) + { + _logger = logger; + } - [HttpGet] - public IEnumerable Get() - { - var rng = new Random(); - var temperatureC = rng.Next(-20, 55); + [HttpGet(Name = "GetWeatherForecast")] + public IEnumerable Get() + { + var rng = new Random(); + var temperatureC = rng.Next(-20, 55); - _logger.LogTrace($"Trace Temperature: {temperatureC}"); - _logger.LogDebug($"Debug Temperature: {temperatureC}"); - _logger.LogInformation($"Information Temperature: {temperatureC}"); - _logger.LogWarning($"Warning Temperature: {temperatureC}"); - _logger.LogError($"Error Temperature: {temperatureC}"); - _logger.LogCritical($"Critical Temperature: {temperatureC}"); + _logger.LogTrace($"Trace Temperature: {temperatureC}"); + _logger.LogDebug($"Debug Temperature: {temperatureC}"); + _logger.LogInformation($"Information Temperature: {temperatureC}"); + _logger.LogWarning($"Warning Temperature: {temperatureC}"); + _logger.LogError($"Error Temperature: {temperatureC}"); + _logger.LogCritical($"Critical Temperature: {temperatureC}"); - return Enumerable.Range(1, 5).Select(index => new WeatherForecast - { - Date = DateTime.Now.AddDays(index), - TemperatureC = temperatureC, - Summary = Summaries[rng.Next(Summaries.Length)] - }) - .ToArray(); - } + return Enumerable.Range(1, 5).Select(index => new WeatherForecast + { + Date = DateTime.Now.AddDays(index), + TemperatureC = temperatureC, + Summary = Summaries[rng.Next(Summaries.Length)] + }) + .ToArray(); } } \ No newline at end of file diff --git a/examples/WebApp/Program.cs b/examples/WebApp/Program.cs index 5c0ee27..8b61615 100644 --- a/examples/WebApp/Program.cs +++ b/examples/WebApp/Program.cs @@ -1,31 +1,31 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Hosting; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.Hosting; -using Microsoft.Extensions.Logging; using X.Extensions.Logging.Telegram; -namespace WebApp +var builder = WebApplication.CreateBuilder(args); + +// Add services to the container. + +builder.Services.AddControllers(); +// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle +builder.Services.AddEndpointsApiExplorer(); +builder.Services.AddSwaggerGen(); + +builder.Logging.ClearProviders(); +builder.Logging.AddConsole(); +builder.Logging.AddTelegram(builder.Configuration); + +var app = builder.Build(); + +// Configure the HTTP request pipeline. +if (app.Environment.IsDevelopment()) { - public class Program - { - public static void Main(string[] args) - { - CreateHostBuilder(args).Build().Run(); - } - - public static IHostBuilder CreateHostBuilder(string[] args) => - Host.CreateDefaultBuilder(args) - .ConfigureLogging((context, builder) => - { - if (context.Configuration != null) - builder - .AddTelegram(context.Configuration) - .AddConsole(); - }) - .ConfigureWebHostDefaults(webBuilder => { webBuilder.UseStartup(); }); - } -} \ No newline at end of file + app.UseSwagger(); + app.UseSwaggerUI(); +} + +app.UseHttpsRedirection(); + +app.UseAuthorization(); + +app.MapControllers(); + +app.Run(); \ No newline at end of file diff --git a/examples/WebApp/Properties/launchSettings.json b/examples/WebApp/Properties/launchSettings.json deleted file mode 100644 index 9112ef3..0000000 --- a/examples/WebApp/Properties/launchSettings.json +++ /dev/null @@ -1,31 +0,0 @@ -{ - "$schema": "http://json.schemastore.org/launchsettings.json", - "iisSettings": { - "windowsAuthentication": false, - "anonymousAuthentication": true, - "iisExpress": { - "applicationUrl": "http://localhost:40753", - "sslPort": 44356 - } - }, - "profiles": { - "IIS Express": { - "commandName": "IISExpress", - "launchBrowser": true, - "launchUrl": "swagger", - "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" - } - }, - "WebApp": { - "commandName": "Project", - "dotnetRunMessages": "true", - "launchBrowser": true, - "launchUrl": "swagger", - "applicationUrl": "https://localhost:5001;http://localhost:5000", - "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" - } - } - } -} diff --git a/examples/WebApp/Startup.cs b/examples/WebApp/Startup.cs deleted file mode 100644 index 01c69ba..0000000 --- a/examples/WebApp/Startup.cs +++ /dev/null @@ -1,52 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.HttpsPolicy; -using Microsoft.AspNetCore.Mvc; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; -using Microsoft.Extensions.Logging; -using Microsoft.OpenApi.Models; - -namespace WebApp -{ - public class Startup - { - public Startup(IConfiguration configuration) - { - 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) - { - services.AddControllers(); - services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo {Title = "WebApp", 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) - { - if (env.IsDevelopment()) - { - app.UseDeveloperExceptionPage(); - app.UseSwagger(); - app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "WebApp v1")); - } - - app.UseHttpsRedirection(); - - app.UseRouting(); - - app.UseAuthorization(); - - app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); - } - } -} \ No newline at end of file diff --git a/examples/WebApp/WeatherForecast.cs b/examples/WebApp/WeatherForecast.cs index b8e249c..ced35b9 100644 --- a/examples/WebApp/WeatherForecast.cs +++ b/examples/WebApp/WeatherForecast.cs @@ -1,15 +1,12 @@ -using System; +namespace WebApp; -namespace WebApp +public class WeatherForecast { - public class WeatherForecast - { - public DateTime Date { get; set; } + public DateTime Date { get; set; } - public int TemperatureC { get; set; } + public int TemperatureC { get; set; } - public int TemperatureF => 32 + (int) (TemperatureC / 0.5556); + public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); - public string Summary { get; set; } - } + public string? Summary { get; set; } } \ No newline at end of file diff --git a/examples/WebApp/WebApp.csproj b/examples/WebApp/WebApp.csproj index c2d8f0b..65c8f4c 100644 --- a/examples/WebApp/WebApp.csproj +++ b/examples/WebApp/WebApp.csproj @@ -1,12 +1,13 @@ - netcoreapp3.1 + net6.0 + enable + enable + default - - diff --git a/examples/WebApp/appsettings.Development.json b/examples/WebApp/appsettings.Development.json index 8983e0f..0c208ae 100644 --- a/examples/WebApp/appsettings.Development.json +++ b/examples/WebApp/appsettings.Development.json @@ -2,8 +2,7 @@ "Logging": { "LogLevel": { "Default": "Information", - "Microsoft": "Warning", - "Microsoft.Hosting.Lifetime": "Information" + "Microsoft.AspNetCore": "Warning" } } } diff --git a/examples/WebApp/appsettings.json b/examples/WebApp/appsettings.json index b2ff47d..f1e188e 100644 --- a/examples/WebApp/appsettings.json +++ b/examples/WebApp/appsettings.json @@ -2,13 +2,11 @@ "Logging": { "LogLevel": { "Default": "Information", - "Microsoft": "Warning", - "Microsoft.Hosting.Lifetime": "Information" + "Microsoft.AspNetCore": "Warning" }, "Telegram": { "LogLevel": { - "Default": "Error", - "WebApp.Controllers": "Warning" + "Default": "Error" }, "AccessToken": "1234567890:AAAaaAAaa_AaAAaa-AAaAAAaAAaAaAaAAAA", "ChatId": "-0000000000000", @@ -17,4 +15,4 @@ } }, "AllowedHosts": "*" -} \ No newline at end of file +} diff --git a/src/X.Extensions.Logging.Telegram/TelegramLogger.cs b/src/X.Extensions.Logging.Telegram/TelegramLogger.cs index 634a300..52b6854 100644 --- a/src/X.Extensions.Logging.Telegram/TelegramLogger.cs +++ b/src/X.Extensions.Logging.Telegram/TelegramLogger.cs @@ -17,6 +17,7 @@ internal TelegramLogger( ITelegramMessageFormatter formatter) { Options = options ?? throw new ArgumentNullException(nameof(options)); + _logLevelChecker = logLevelChecker; _queueProcessor = loggerProcessor; _formatter = formatter; diff --git a/src/X.Extensions.Logging.Telegram/X.Extensions.Logging.Telegram.csproj b/src/X.Extensions.Logging.Telegram/X.Extensions.Logging.Telegram.csproj index 1be8c3a..2c3a55c 100644 --- a/src/X.Extensions.Logging.Telegram/X.Extensions.Logging.Telegram.csproj +++ b/src/X.Extensions.Logging.Telegram/X.Extensions.Logging.Telegram.csproj @@ -1,7 +1,7 @@ - 10 + default Andrew Gubskiy True X.Extensions.Logging.Telegram @@ -12,14 +12,14 @@ telegram, logging, log, logs, tg Telegram logging provider git - 1.0.5.1 - netstandard2.0 - 1.0.5.1 + 1.0.6.1 + 1.0.6.1 + net6.0;net7.0;netstandard2.0;netstandard2.1 - - + + diff --git a/tests/X.Extensions.Logging.Telegram.Tests/X.Extensions.Logging.Telegram.Tests.csproj b/tests/X.Extensions.Logging.Telegram.Tests/X.Extensions.Logging.Telegram.Tests.csproj index d77f834..b2a96f4 100644 --- a/tests/X.Extensions.Logging.Telegram.Tests/X.Extensions.Logging.Telegram.Tests.csproj +++ b/tests/X.Extensions.Logging.Telegram.Tests/X.Extensions.Logging.Telegram.Tests.csproj @@ -4,12 +4,14 @@ net6.0 false + + default - - + +