Files
server/src/Api/Program.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

48 lines
1.7 KiB
C#
Raw Normal View History

2020-01-10 08:33:13 -05:00
using AspNetCoreRateLimit;
2019-07-23 16:38:49 -04:00
using Bit.Core.Utilities;
using Microsoft.IdentityModel.Tokens;
using Serilog.Events;
2016-05-19 19:10:24 -04:00
namespace Bit.Api;
2022-08-29 16:06:55 -04:00
2016-05-19 19:10:24 -04:00
public class Program
{
public static void Main(string[] args)
{
2020-01-10 08:33:13 -05:00
Host
2017-10-06 12:18:16 -04:00
.CreateDefaultBuilder(args)
.ConfigureCustomAppConfiguration(args)
2020-01-10 08:33:13 -05:00
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
webBuilder.ConfigureLogging((hostingContext, logging) =>
logging.AddSerilog(hostingContext, e =>
2022-08-29 16:06:55 -04:00
{
2020-01-10 08:33:13 -05:00
var context = e.Properties["SourceContext"].ToString();
if (e.Exception != null &&
2020-01-10 08:33:13 -05:00
(e.Exception.GetType() == typeof(SecurityTokenValidationException) ||
e.Exception.Message == "Bad security stamp."))
2019-07-23 16:38:49 -04:00
{
2020-01-10 08:33:13 -05:00
return false;
}
2019-07-23 16:38:49 -04:00
if (e.Level == LogEventLevel.Information &&
2020-01-10 08:33:13 -05:00
context.Contains(typeof(IpRateLimitMiddleware).FullName))
{
return true;
}
2019-07-23 16:38:49 -04:00
if (context.Contains("IdentityServer4.Validation.TokenValidator") ||
2020-01-10 08:33:13 -05:00
context.Contains("IdentityServer4.Validation.TokenRequestValidator"))
{
return e.Level > LogEventLevel.Error;
}
2019-07-23 16:38:49 -04:00
2020-01-10 08:33:13 -05:00
return e.Level >= LogEventLevel.Error;
}));
})
2017-10-06 12:18:16 -04:00
.Build()
.Run();
2016-05-19 19:10:24 -04:00
}
}