title: Use IWebHostEnvironment in Program.cs web host builder in ASP.NET Core 3.1
body: <p>I have an ASP.NET Core 3.1 application, and I need to access the <code>IWebHostEnvironment</code> in the <code>Program.cs</code> web host builder. This is what I have right now (<code>Program.cs</code>):</p>
  <pre class="lang-cs prettyprint-override"><code>public class Program {
  
      public static void Main(string[] args) {
          CreateWebHostBuilder(args).Build().Run();
      }
  
      private static bool IsDevelopment =&gt; 
          Environment.GetEnvironmentVariable(&quot;ASPNETCORE_ENVIRONMENT&quot;) == &quot;Development&quot;;
  
      public static string HostPort =&gt; 
          IsDevelopment 
              ? &quot;5000&quot; 
              : Environment.GetEnvironmentVariable(&quot;PORT&quot;);
  
      public static IWebHostBuilder CreateWebHostBuilder(string[] args) =&gt;
          WebHost.CreateDefaultBuilder(args)
              .UseUrls($&quot;http://+:{HostPort}&quot;)
              .UseSerilog((context, config) =&gt; {
                  config.ReadFrom.Configuration(context.Configuration);
              })
              .UseStartup&lt;Startup&gt;();
  }
  </code></pre>
  <p>Instead of doing the <code>IsDevelopment</code> check the way I do it, I would like to use the <code>IsDevelopment()</code> method from <code>IWebHostEnvironment</code>, not entirely sure how to do that. What I have right now works, but honestly it doesn't &quot;feel right&quot;.</p>