Skip to content

Instantly share code, notes, and snippets.

View JuergenGutsch's full-sized avatar
🏠
Working from home

Juergen Gutsch JuergenGutsch

🏠
Working from home
View GitHub Profile
<?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"
internalLogLevel="Warn"
internalLogFile="C:\git\dotnetconf\001-logging\internal-nlog.txt">
<!-- Load the ASP.NET Core plugin -->
<extensions>
<add assembly="NLog.Web.AspNetCore"/>
using System.Collections.Concurrent;
namespace LoggingSample;
public class ColoredConsoleLoggerConfiguration
{
public LogLevel LogLevel { get; set; } = LogLevel.Warning;
public int EventId { get; set; } = 0;
public ConsoleColor Color { get; set; } = ConsoleColor.Yellow;
}
using System;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
namespace HostedServiceSample
{
public class SampleHostedService : IHostedService
{
public class StopwatchMiddleWare
{
private readonly RequestDelegate _next;
public StopwatchMiddleWare(RequestDelegate next)
{
_next = next;
}
public async Task Invoke(HttpContext context)
using System.Text;
using Microsoft.AspNetCore.Mvc.Formatters;
using Microsoft.Net.Http.Headers;
using OutputFormatterSample.Models;
namespace OutputFormatterSample;
public class VcardOutputFormatter : TextOutputFormatter
{
public string ContentType { get; } = "text/vcard";
using System.Globalization;
using System.Text;
using CsvHelper;
using Microsoft.AspNetCore.Mvc.Formatters;
using Microsoft.Net.Http.Headers;
using OutputFormatterSample.Models;
namespace OutputFormatterSample;
public class CsvOutputFormatter : TextOutputFormatter
namespace HostedServiceSample;
public class SampleBackgroundService : BackgroundService
{
private readonly ILogger<SampleHostedService> logger;
public SampleBackgroundService(ILogger<SampleHostedService> logger)
{
this.logger = logger;
}
namespace RoutingSample;
public class MyHealthChecksMiddleware
{
private readonly ILogger<MyHealthChecksMiddleware> _logger;
public MyHealthChecksMiddleware(
RequestDelegate next,
ILogger<MyHealthChecksMiddleware> logger)
{
namespace RoutingSample;
public static class MapMyHealthChecksExtensions
{
public static IEndpointConventionBuilder MapMyHealthChecks(
this IEndpointRouteBuilder endpoints, string pattern = "/myhealth")
{
var pipeline = endpoints
.CreateApplicationBuilder()
.UseMiddleware<MyHealthChecksMiddleware>()
.Build();
public class PersonsCsvBinder : IModelBinder
{
public Task BindModelAsync(ModelBindingContext bindingContext)
{
if (bindingContext == null)
{
throw new ArgumentNullException(nameof(bindingContext));
}
// Specify a default argument name if none is set by ModelBinderAttribute