A simple Asp.Net core application contains a Startup.cs file and a Program.cs file. We saw that the
Startup file is used to define the execution pipeline to process Http requests
and to inject services. In this post we shall see about the role of Program.cs
file.
The Program.cs file in an Asp.Net core application contains logic to define the host configuration and logging configuration. It has the public static void Main() method which is the entry point of the application.
The Main() method calls CreateWebHostBuilder, which in-turn calls WebHost.CreateDefaultBuilder, this method performs the following tasks under the hood.
The Program.cs file in an Asp.Net core application contains logic to define the host configuration and logging configuration. It has the public static void Main() method which is the entry point of the application.
The Main() method calls CreateWebHostBuilder, which in-turn calls WebHost.CreateDefaultBuilder, this method performs the following tasks under the hood.
Ø
Configures Kestrel server as the web server
Ø
Sets the content root to the path returned by
Directory.GetCurrentDirectory
Ø
Loads host configuration from Environment
variables / command line args
Ø
Loads app configuration from appsettings.json. /
Environment variables. / Command-line arguments
Ø
Configures logging for console and debug output,
includes log filtering rules specified in a Logging configuration section of an
appsettings.json
Ø
Enables IIS Integration
The CreateDefaultBuilder does the above automatically using the default settings, we can customize configuration and logging and overriding the default behavior using ConfigureAppConfiguration & ConfigureLogging methods.
No comments:
Post a Comment