1- using System ;
1+ using BlazorLogger ;
2+ using System ;
23using System . Threading . Tasks ;
34
45namespace BlazorDB . Storage
56{
6- internal static class Logger
7+ internal class BlazorDBLogger : IBlazorDBLogger
78 {
89 private const string Blue = "color: blue; font-style: bold;" ;
910 private const string Green = "color: green; font-style: bold;" ;
1011 private const string Red = "color: red; font-style: bold;" ;
1112 private const string Normal = "color: black; font-style: normal;" ;
1213 internal static bool LogDebug { get ; set ; } = true ;
1314
14- internal async static Task LogStorageSetToConsole ( Type type , object list )
15+ private ILogger _logger ;
16+ public BlazorDBLogger ( ILogger logger )
17+ {
18+ _logger = logger ;
19+ }
20+
21+ public async Task LogStorageSetToConsole ( Type type , object list )
1522 {
1623 if ( ! LogDebug ) return ;
17- await BlazorLogger . Logger . Log ( $ "StorageSet<{ type . GetGenericArguments ( ) [ 0 ] . Name } >: %o", list ) ;
24+ await _logger . Log ( $ "StorageSet<{ type . GetGenericArguments ( ) [ 0 ] . Name } >: %o", list ) ;
1825 }
1926
20- internal async static Task StartContextType ( Type contextType , bool loading = true )
27+ public async Task StartContextType ( Type contextType , bool loading = true )
2128 {
2229 if ( ! LogDebug ) return ;
2330 var message = loading ? "loading" : "log" ;
24- await BlazorLogger . Logger . GroupCollapsed ( $ "Context { message } : %c{ contextType . Namespace } .{ contextType . Name } ", Blue ) ;
31+ await _logger . GroupCollapsed ( $ "Context { message } : %c{ contextType . Namespace } .{ contextType . Name } ", Blue ) ;
2532 }
2633
27- internal async static Task ContextSaved ( Type contextType )
34+ public async Task ContextSaved ( Type contextType )
2835 {
2936 if ( ! LogDebug ) return ;
30- await BlazorLogger . Logger . GroupCollapsed ( $ "Context %csaved: %c{ contextType . Namespace } .{ contextType . Name } ", Green ,
37+ await _logger . GroupCollapsed ( $ "Context %csaved: %c{ contextType . Namespace } .{ contextType . Name } ", Green ,
3138 Blue ) ;
3239 }
3340
34- internal static void StorageSetSaved ( Type modelType , int count )
41+ public void StorageSetSaved ( Type modelType , int count )
3542 {
3643 if ( ! LogDebug ) return ;
37- BlazorLogger . Logger . Log (
44+ _logger . Log (
3845 $ "StorageSet %csaved: %c{ modelType . Namespace } .{ modelType . Name } %c with { count } items", Green , Blue ,
3946 Normal ) ;
4047 }
4148
42- internal static void EndGroup ( )
49+ public void EndGroup ( )
4350 {
4451 if ( ! LogDebug ) return ;
45- BlazorLogger . Logger . GroupEnd ( ) ;
52+ _logger . GroupEnd ( ) ;
4653 }
4754
48- internal static void ItemAddedToContext ( string contextTypeName , Type modelType , object item )
55+ public void ItemAddedToContext ( string contextTypeName , Type modelType , object item )
4956 {
5057 if ( ! LogDebug ) return ;
51- BlazorLogger . Logger . GroupCollapsed (
58+ _logger . GroupCollapsed (
5259 $ "Item %c{ modelType . Namespace } .{ modelType . Name } %c %cadded%c to context: %c{ contextTypeName } ", Blue ,
5360 Normal , Green , Normal , Blue ) ;
54- BlazorLogger . Logger . Log ( "Item: %o" , item ) ;
55- BlazorLogger . Logger . GroupEnd ( ) ;
61+ _logger . Log ( "Item: %o" , item ) ;
62+ _logger . GroupEnd ( ) ;
5663 }
5764
58- internal static void LoadModelInContext ( Type modelType , int count )
65+ public void LoadModelInContext ( Type modelType , int count )
5966 {
6067 if ( ! LogDebug ) return ;
61- BlazorLogger . Logger . Log (
68+ _logger . Log (
6269 $ "StorageSet loaded: %c{ modelType . Namespace } .{ modelType . Name } %c with { count } items", Blue , Normal ) ;
6370 }
6471
65- internal static void ItemRemovedFromContext ( string contextTypeName , Type modelType )
72+ public void ItemRemovedFromContext ( string contextTypeName , Type modelType )
6673 {
6774 if ( ! LogDebug ) return ;
68- BlazorLogger . Logger . Log (
75+ _logger . Log (
6976 $ "Item %c{ modelType . Namespace } .{ modelType . Name } %c %cremoved%c from context: %c{ contextTypeName } ", Blue ,
7077 Normal , Red , Normal , Blue ) ;
7178 }
79+
80+ public void Error ( string error )
81+ {
82+ //Always log errors
83+ _logger . Error ( error ) ;
84+ }
7285 }
7386}
0 commit comments