I got it resolved now, details are given in https://rinkusitecore.wordpress.com/2024/04/14/sitecore-logging-user-login-attempts-for-success-failure-scenario/
Logging Successful Login
Its striaghtforward, for it used a patch after CookieAuthentication.SignIn.UpdateUserProperties processor and wrote code in its process method.
If you are not using IdentityServer as middleware due to any reason(e.g. some issue came in its configuration) but OOTB basic authentication, then just hook into “Sitecore.Pipelines.LoggingIn.CheckClientUser” processor(e.g. use your custom processor to check authentication and then you can write your logging code in it).
At identity server we have created a custom JS file(loginattemptlogger.js), in \sitecore\Sitecore.Plugin.IdentityServer\Content\lib) and placed below code:
Then we include this file in LayoutFile which shows login UI (\sitecore\Sitecore.Plugin.IdentityServer\Views\Shared)
Here custom OwinCookieAuthenticationSignin class is inherited from SignInProcessor.
This process also works whether we use IdentityServer as middleware or using basic authentication.
Logging Failure Login
As we are using default owin authentication (which intern uses claims) so somehow not able to track failure case, i have tried with placing processor at each different step on Sitecore.Pipelines.LoggingIn (LoggedIn won’t won’t work as we need to track failure case)
Now everything looks good but it was not the case as when tried to call our api from this JS file we got CSP error.
To get rid of it, we had to do some update on IdentyServer config file (/sitecore/Sitecore.Plugin.IdentityServer/Config/identityServer.xml) and replaced its ContentSecurityPolicy section with
default-src 'self'; object-src 'none'; style-src 'self' https://fonts.googleapis.com; font-src 'self' https://fonts.gstatic.com; frame-ancestors {AllowedCorsOrigin:Sitecore}; sandbox allow-forms allow-same-origin allow-scripts; base-uri 'self'; connect-src 'self' {AllowedCorsOrigin:Sitecore}