Skip to content

Making it simple to customize Hosting for your .NET Core 6.x+ application

License

Notifications You must be signed in to change notification settings

PureKrome/SimpleHosting

Repository files navigation

Simple: Hosting

Making it simple to customize Hosting for your ASP.NET Core 6.x+ application

Key Points

  • 🚀 Reduces boilerplate ceremony for your program.cs file.
  • ✅ Sets up Serilog around the entire application. (:wrench: Configure all settings via your appsettings.json file(s))
  • ✅ Simple to add some extra (helpful) log header/footer.
  • ✅ Can also add logging to your Startup class (new with ASP.NET Core 6+)

In summary: this library makes is SIMPLE (by abstracting away most of the boring ceremony) to setup your ASP.NET Core application.


Installation

Package is available via NuGet.

dotnet add package WorldDomination.SimpleHosting 

More Information:

Basically, turn your program.cs into this :

public static Task Main(string[] args)
{
    return WorldDomination.SimpleHosting.Program.Main<Startup>(args);
}

and you've now got some Serilog all wired up along with some nice application-wide error handling.

For more custom settings:

public static Task Main(string[] args)
{
    // Every Option here is optional.
    // Set what you want.
    var options = new MainOptions
    {
        CommandLineArguments = args,
        FirstLoggingInformationMessage = "~~ Sample Web Application ~~",
        LogAssemblyInformation = true,
        LastLoggingInformationMessage = "-- Sample Web Application has ended/terminated --",
        StartupActivation = new System.Func<WebHostBuilderContext, ILogger, Startup>((context, logger) => new Startup(context.Configuration, logger))
    };

    return SimpleHosting.Program.Main<Startup>(options);
}

Contribute

Yep - contributions are always welcome. Please read the contribution guidelines first.

Code of Conduct

If you wish to participate in this repository then you need to abide by the code of conduct.

Feedback

Yes! Please use the Issues section to provide feedback - either good or needs improvement 🆒