int
int
CC#
Created by int on 1/28/2024 in #help
"Application started" after "Application is shutting down"
c#
var builder = Host.CreateApplicationBuilder(args);
builder.Logging.AddConsole();
builder.Services.AddSingleton<IDatabaseSerializer, EqualsDatabaseSerializer>();
builder.Services.AddSingleton<Database>();
builder.Services.AddHostedService<App>();

var host = builder.Build();
await host.RunAsync();
c#
var builder = Host.CreateApplicationBuilder(args);
builder.Logging.AddConsole();
builder.Services.AddSingleton<IDatabaseSerializer, EqualsDatabaseSerializer>();
builder.Services.AddSingleton<Database>();
builder.Services.AddHostedService<App>();

var host = builder.Build();
await host.RunAsync();
info: Kevin.App[0]
Listening on port localhost:5371
info: Microsoft.Hosting.Lifetime[0]
Application is shutting down...
info: Microsoft.Hosting.Lifetime[0]
Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
Hosting environment: Production
info: Microsoft.Hosting.Lifetime[0]
Content root path: C:\Users\ \Desktop\Dev\Projects\Kevin
info: Kevin.App[0]
Listening on port localhost:5371
info: Microsoft.Hosting.Lifetime[0]
Application is shutting down...
info: Microsoft.Hosting.Lifetime[0]
Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
Hosting environment: Production
info: Microsoft.Hosting.Lifetime[0]
Content root path: C:\Users\ \Desktop\Dev\Projects\Kevin
8 replies
CC#
Created by int on 8/12/2023 in #help
✅ InitializeComponent not being found, but `dotnet run` works?
13 replies
CC#
Created by int on 7/19/2023 in #help
✅ Respond with HTML instead of plaintext
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();

app.MapGet("/", () => "<h1>Hello World!</h1>");

app.Run();
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();

app.MapGet("/", () => "<h1>Hello World!</h1>");

app.Run();
This is my entire app right now - how do I make the entire app use HTML as the content type by default?
8 replies
CC#
Created by int on 6/30/2023 in #help
❔ How to log using hosts?
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;

var builder = new HostApplicationBuilder();
builder.Logging.ClearProviders();
builder.Logging.AddConsole();
builder.Services.AddLogging();

using var host = builder.Build();

var logger = host.Services.GetRequiredService<ILogger>();

logger.LogInformation("🙂");

await host.RunAsync();
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;

var builder = new HostApplicationBuilder();
builder.Logging.ClearProviders();
builder.Logging.AddConsole();
builder.Services.AddLogging();

using var host = builder.Build();

var logger = host.Services.GetRequiredService<ILogger>();

logger.LogInformation("🙂");

await host.RunAsync();
the error is on when I try to get the logger service: Unhandled exception. System.InvalidOperationException: No service for type 'Microsoft.Extensions.Logging.ILogger' has been registered. i thought i had already registered the logging service: builder.Services.AddLogging();
15 replies