0% found this document useful (0 votes)
4 views

dot net code to configure api server

The document is a C# program that sets up a web application using ASP.NET Core and Serilog for logging. It configures the application to read settings from JSON files and environment variables, and it handles exceptions during the hosting process. The application is set to run on HTTP at port 5099 and uses a Startup class for configuration.

Uploaded by

Zak
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

dot net code to configure api server

The document is a C# program that sets up a web application using ASP.NET Core and Serilog for logging. It configures the application to read settings from JSON files and environment variables, and it handles exceptions during the hosting process. The application is set to run on HTTP at port 5099 and uses a Startup class for configuration.

Uploaded by

Zak
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

using Microsoft.

AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Serilog;
using System;
using System.IO;

namespace Wallet.App
{
public class Program
{
public static IConfiguration Configuration { get; } = new
ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
.AddJsonFile($"appsettings.
{Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ??
"Production"}.json", optional: true)
.AddEnvironmentVariables()
.Build();

public static void Main(string[] args)


{
Log.Logger = new LoggerConfiguration()
.ReadFrom.Configuration(Configuration)
.Enrich.FromLogContext()
.CreateLogger();
try

{
Log.Information("Setting up the environment...");
CreateWebHostBuilder(args).Build().Run();
return;
}
catch (Exception ex)
{
Log.Fatal(ex, "Host terminated unexpectedly");
return;
}
finally
{
Log.CloseAndFlush();
}

public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>


WebHost.CreateDefaultBuilder(args)
.UseSerilog((context, config) =>
{
config.ReadFrom.Configuration(context.Configuration);
})
.UseStartup<Startup>()
.UseUrls("http://*:5099");
}
}

You might also like