4
4
using LinkDotNet . Blog . Infrastructure . Persistence ;
5
5
using Microsoft . AspNetCore . Components ;
6
6
using Microsoft . AspNetCore . Components . Authorization ;
7
+ using Microsoft . Extensions . Logging ;
7
8
8
9
namespace LinkDotNet . Blog . Web . Features . Services ;
9
10
@@ -13,17 +14,20 @@ public class UserRecordService : IUserRecordService
13
14
private readonly NavigationManager navigationManager ;
14
15
private readonly AuthenticationStateProvider authenticationStateProvider ;
15
16
private readonly ILocalStorageService localStorageService ;
17
+ private readonly ILogger < UserRecordService > logger ;
16
18
17
19
public UserRecordService (
18
20
IRepository < UserRecord > userRecordRepository ,
19
21
NavigationManager navigationManager ,
20
22
AuthenticationStateProvider authenticationStateProvider ,
21
- ILocalStorageService localStorageService )
23
+ ILocalStorageService localStorageService ,
24
+ ILogger < UserRecordService > logger )
22
25
{
23
26
this . userRecordRepository = userRecordRepository ;
24
27
this . navigationManager = navigationManager ;
25
28
this . authenticationStateProvider = authenticationStateProvider ;
26
29
this . localStorageService = localStorageService ;
30
+ this . logger = logger ;
27
31
}
28
32
29
33
public async ValueTask StoreUserRecordAsync ( )
@@ -34,7 +38,7 @@ public async ValueTask StoreUserRecordAsync()
34
38
}
35
39
catch ( Exception e )
36
40
{
37
- Console . Write ( $ "Exception : { e } " ) ;
41
+ logger . LogError ( "Error while storing user record service : {Exception}" , e ) ;
38
42
}
39
43
}
40
44
@@ -62,7 +66,7 @@ private async ValueTask GetAndStoreUserRecordAsync()
62
66
63
67
private async ValueTask < int > GetIdentifierHashAsync ( )
64
68
{
65
- if ( await TryGetKey ( ) )
69
+ if ( await HasKeyAsync ( ) )
66
70
{
67
71
var key = await localStorageService . GetItemAsync < Guid > ( "user" ) ;
68
72
return key . GetHashCode ( ) ;
@@ -73,7 +77,7 @@ private async ValueTask<int> GetIdentifierHashAsync()
73
77
return id . GetHashCode ( ) ;
74
78
}
75
79
76
- private async ValueTask < bool > TryGetKey ( )
80
+ private async ValueTask < bool > HasKeyAsync ( )
77
81
{
78
82
try
79
83
{
0 commit comments