title: How do I log authorization attempts in .net core
body: <p>I'm trying to write to a log when I person tries to access a method under an Authorize Attribute. Basically, I want to log if a person uses an invalid token or an expired token. I'm using basic Authentication for JWT</p>
  
  <pre><code>services.AddAuthentication(o =&gt;
  {
      o.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
      o.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
  }).AddJwtBearer(cfg =&gt;
      {
          cfg.RequireHttpsMetadata = false;
          cfg.SaveToken = true;
  
          cfg.TokenValidationParameters = new TokenValidationParameters()
          {
              ValidAudience = jwtAudience,
              ValidIssuer = jwtIssuer,
              IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(jwtSecurityKey))
          };
  
      });
  </code></pre>
  
  <p>Is there a way I can add a piece of code to the authorization check that logs if a authorization attempt was valid and why it wasn't?</p>