I have Login post action:
[HttpPost]
public ActionResult Login(LoginModel model, string post)
{
Repo.Resolve<ILogsRepository>().LogLoginAttempt(model.Username, this.Request.UserHostAddress, this.Request.RawUrl);
if (ModelState.IsValid) {
var login = this._authRepository.ValidateCredentials(model.Username, model.Password);
if (login != null) {
Logger.LogAsync(Action.UserSignIn, Level.Log, string.Format("User signed in as '{0}' -> '{1}'", model.Username, login));
return Request.IsAjaxRequest() ? Content("__close__") : ClientCabinet();
}
Logger.LogAsync(Action.UserSignIn, Level.Mandatory, Event.Error, string.Format("User failed to sign in as '{0}': invalid username or password", model.Username));
ModelState.AddModelError("Username", @"login or password is incorrect!");
}
return View(model);
}
And i would like to make logger method async:
public static async Task LogAsync(Action action, Level level, string message) {
Log(action, level, message);
}
So, i want to achieve async actions of Logger after ValidateCredentials returns me correct result.
But, if i add breakpoint into LogAsync or Thread.Sleep, method blocks and still processing synchronuosly.
How can i achieve async execution of method after login is validate?