Skip to content
This repository has been archived by the owner on Oct 27, 2024. It is now read-only.

Commit

Permalink
Merge pull request #20 from ernado-x/19-update-examples
Browse files Browse the repository at this point in the history
Update examples. Close #19
  • Loading branch information
ernado-x authored Mar 5, 2023
2 parents dfe0c47 + 89c2553 commit 44fcd4b
Show file tree
Hide file tree
Showing 21 changed files with 92 additions and 345 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,9 @@ logBuilder.AddTelegram(options, CreateFormatter);
```

For using custom message formatter delegate Func<string, ITelegramMessageFormatter> 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)
9 changes: 1 addition & 8 deletions X.Extensions.Logging.Telegram.sln
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion examples/ConsoleApp/ConsoleApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<LangVersion>10</LangVersion>
<LangVersion>default</LangVersion>
</PropertyGroup>

<ItemGroup>
Expand Down

This file was deleted.

31 changes: 0 additions & 31 deletions examples/WebApp.NextVersion/Program.cs

This file was deleted.

31 changes: 0 additions & 31 deletions examples/WebApp.NextVersion/Properties/launchSettings.json

This file was deleted.

12 changes: 0 additions & 12 deletions examples/WebApp.NextVersion/WeatherForecast.cs

This file was deleted.

17 changes: 0 additions & 17 deletions examples/WebApp.NextVersion/WebApp.NextVersion.csproj

This file was deleted.

8 changes: 0 additions & 8 deletions examples/WebApp.NextVersion/appsettings.Development.json

This file was deleted.

18 changes: 0 additions & 18 deletions examples/WebApp.NextVersion/appsettings.json

This file was deleted.

70 changes: 31 additions & 39 deletions examples/WebApp/Controllers/WeatherForecastController.cs
Original file line number Diff line number Diff line change
@@ -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<WeatherForecastController> _logger;
private readonly ILogger<WeatherForecastController> _logger;

public WeatherForecastController(ILogger<WeatherForecastController> logger)
{
_logger = logger;

_logger.LogWarning("WeatherForecastController created");
}
public WeatherForecastController(ILogger<WeatherForecastController> logger)
{
_logger = logger;
}

[HttpGet]
public IEnumerable<WeatherForecast> Get()
{
var rng = new Random();
var temperatureC = rng.Next(-20, 55);
[HttpGet(Name = "GetWeatherForecast")]
public IEnumerable<WeatherForecast> 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();
}
}
56 changes: 28 additions & 28 deletions examples/WebApp/Program.cs
Original file line number Diff line number Diff line change
@@ -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<Startup>(); });
}
}
app.UseSwagger();
app.UseSwaggerUI();
}

app.UseHttpsRedirection();

app.UseAuthorization();

app.MapControllers();

app.Run();
31 changes: 0 additions & 31 deletions examples/WebApp/Properties/launchSettings.json

This file was deleted.

Loading

0 comments on commit 44fcd4b

Please sign in to comment.