5
5
using LinkDotNet . Infrastructure . Persistence ;
6
6
using Microsoft . AspNetCore . Components ;
7
7
using Microsoft . AspNetCore . Components . Authorization ;
8
+ using Microsoft . Extensions . Logging ;
8
9
9
10
namespace LinkDotNet . Blog . Web . Shared
10
11
{
@@ -19,20 +20,35 @@ public class UserRecordService : IUserRecordService
19
20
private readonly NavigationManager navigationManager ;
20
21
private readonly AuthenticationStateProvider authenticationStateProvider ;
21
22
private readonly ILocalStorageService localStorageService ;
23
+ private readonly ILogger logger ;
22
24
23
25
public UserRecordService (
24
26
IRepository < UserRecord > userRecordRepository ,
25
27
NavigationManager navigationManager ,
26
28
AuthenticationStateProvider authenticationStateProvider ,
27
- ILocalStorageService localStorageService )
29
+ ILocalStorageService localStorageService ,
30
+ ILogger logger )
28
31
{
29
32
this . userRecordRepository = userRecordRepository ;
30
33
this . navigationManager = navigationManager ;
31
34
this . authenticationStateProvider = authenticationStateProvider ;
32
35
this . localStorageService = localStorageService ;
36
+ this . logger = logger ;
33
37
}
34
38
35
39
public async Task StoreUserRecordAsync ( )
40
+ {
41
+ try
42
+ {
43
+ await GetAndStoreUSerRecordAsync ( ) ;
44
+ }
45
+ catch ( Exception e )
46
+ {
47
+ logger . Log ( LogLevel . Error , e , "Couldn't write user record" ) ;
48
+ }
49
+ }
50
+
51
+ private async Task GetAndStoreUSerRecordAsync ( )
36
52
{
37
53
var userIdentity = ( await authenticationStateProvider . GetAuthenticationStateAsync ( ) ) . User . Identity ;
38
54
if ( userIdentity == null || userIdentity . IsAuthenticated )
0 commit comments