Skip to content

Instantly share code, notes, and snippets.

@ViMaSter
Created April 29, 2021 06:35
Show Gist options
  • Save ViMaSter/1a357ee06a750c4ddc893f4a5e0b4679 to your computer and use it in GitHub Desktop.
Save ViMaSter/1a357ee06a750c4ddc893f4a5e0b4679 to your computer and use it in GitHub Desktop.
using System.IO;
using System.Linq;
using System.Reflection;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
namespace m2m_api
{
public static class Program
{
private static string GetCustomAttributeFromAssembly(string key)
{
return Assembly.GetExecutingAssembly().CustomAttributes.Where(c => c.ConstructorArguments.Count >= 2 && c.ConstructorArguments[0].Value as string == key).Select(c => c.ConstructorArguments[1].Value as string).FirstOrDefault();
}
public static void Main(string[] args)
{
var builder = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", true, true)
.AddEnvironmentVariables();
var configuration = builder.Build();
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
if (!string.IsNullOrEmpty(configuration["Sentry:DSN"]))
{
webBuilder.UseSentry(options =>
{
options.Release = GetCustomAttributeFromAssembly("GitHash");
if (string.IsNullOrEmpty(options.Release))
{
options.Release = "n/a";
}
options.Dsn = configuration["Sentry:DSN"];
options.Environment = configuration.GetSection("KeyStorage:BlobName")?.Value?.Replace(".xml", "")?.ToLower() ?? "undefined";
});
}
})
.Build()
.Run();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment