33using System . Collections . Immutable ;
44using System . Diagnostics ;
55using System . Diagnostics . CodeAnalysis ;
6- using System . IO ;
7- using System . Linq ;
86using System . Net ;
9- using System . Net . Http ;
107using System . Net . Http . Headers ;
118using System . Reflection ;
129using System . Text . Json ;
1310using System . Text . Json . Serialization ;
14- using System . Threading ;
15- using System . Threading . Tasks ;
1611using Apizr ;
1712using Apizr . Logging ;
1813using AsyncAwaitBestPractices ;
4742using Polly . Extensions . Http ;
4843using Polly . Timeout ;
4944using Refit ;
50- using Sentry ;
5145using StabilityMatrix . Avalonia . Behaviors ;
5246using StabilityMatrix . Avalonia . Helpers ;
5347using StabilityMatrix . Avalonia . Languages ;
@@ -450,7 +444,7 @@ internal static IServiceCollection ConfigureServices()
450444
451445 Config = new ConfigurationBuilder ( )
452446 . SetBasePath ( Directory . GetCurrentDirectory ( ) )
453- . AddJsonFile ( "appsettings.json" , optional : true , reloadOnChange : true )
447+ . AddJsonFile ( "appsettings.json" , optional : true , reloadOnChange : false )
454448 . AddEnvironmentVariables ( )
455449 . Build ( ) ;
456450
@@ -536,11 +530,12 @@ internal static IServiceCollection ConfigureServices()
536530 if ( retryCount > 3 )
537531 {
538532 Logger . Info (
539- "Retry attempt {Count}/{Max} after {Seconds:N2}s due to {Exception }" ,
533+ "Retry attempt {Count}/{Max} after {Seconds:N2}s due to ({Status}) {Msg }" ,
540534 retryCount ,
541535 6 ,
542536 timeSpan . TotalSeconds ,
543- result . Exception ? . ToString ( )
537+ result ? . Result ? . StatusCode ,
538+ result ? . Result ? . ToString ( )
544539 ) ;
545540 }
546541 }
@@ -563,11 +558,12 @@ internal static IServiceCollection ConfigureServices()
563558 if ( retryCount > 4 )
564559 {
565560 Logger . Info (
566- "Retry attempt {Count}/{Max} after {Seconds:N2}s due to {Exception }" ,
561+ "Retry attempt {Count}/{Max} after {Seconds:N2}s due to ({Status}) {Msg }" ,
567562 retryCount ,
568563 7 ,
569564 timeSpan . TotalSeconds ,
570- result . Exception ? . ToString ( )
565+ result ? . Result ? . StatusCode ,
566+ result ? . Result ? . ToString ( )
571567 ) ;
572568 }
573569 }
@@ -612,6 +608,20 @@ internal static IServiceCollection ConfigureServices()
612608 } )
613609 . AddPolicyHandler ( retryPolicyLonger ) ;
614610
611+ services
612+ . AddRefitClient < ILykosModelDiscoveryApi > ( defaultRefitSettings )
613+ . ConfigureHttpClient ( c =>
614+ {
615+ c . BaseAddress = new Uri ( "https://discovery.lykos.ai/api/v1" ) ;
616+ c . Timeout = TimeSpan . FromHours ( 1 ) ;
617+ c . DefaultRequestHeaders . Authorization = new AuthenticationHeaderValue ( "Bearer" , "" ) ;
618+ } )
619+ . AddPolicyHandler ( retryPolicy )
620+ . AddHttpMessageHandler (
621+ serviceProvider =>
622+ new TokenAuthHeaderHandler ( serviceProvider . GetRequiredService < LykosAuthTokenProvider > ( ) )
623+ ) ;
624+
615625 services
616626 . AddRefitClient < IPyPiApi > ( defaultRefitSettings )
617627 . ConfigureHttpClient ( c =>
@@ -1061,10 +1071,53 @@ private static LoggingConfiguration ConfigureLogging()
10611071 . ForLogger ( )
10621072 . FilterMinLevel ( NLog . LogLevel . Trace )
10631073 . WriteTo (
1064- new ConsoleTarget ( "console" )
1074+ new ColoredConsoleTarget ( "console" )
10651075 {
1066- Layout = "[${level:uppercase=true}]\t ${logger:shortName=true}\t ${message}" ,
1067- DetectConsoleAvailable = true
1076+ Layout =
1077+ "[${level:uppercase=true}]\t ${logger:shortName=true}\t ${message}${onexception:\n ${exception:format=tostring}}" ,
1078+ DetectConsoleAvailable = true ,
1079+ EnableAnsiOutput = true ,
1080+ WordHighlightingRules =
1081+ {
1082+ new ConsoleWordHighlightingRule (
1083+ "[TRACE]" ,
1084+ ConsoleOutputColor . DarkGray ,
1085+ ConsoleOutputColor . NoChange
1086+ ) ,
1087+ new ConsoleWordHighlightingRule (
1088+ "[DEBUG]" ,
1089+ ConsoleOutputColor . Gray ,
1090+ ConsoleOutputColor . NoChange
1091+ ) ,
1092+ new ConsoleWordHighlightingRule (
1093+ "[INFO]" ,
1094+ ConsoleOutputColor . DarkGreen ,
1095+ ConsoleOutputColor . NoChange
1096+ ) ,
1097+ new ConsoleWordHighlightingRule (
1098+ "[WARN]" ,
1099+ ConsoleOutputColor . Yellow ,
1100+ ConsoleOutputColor . NoChange
1101+ ) ,
1102+ new ConsoleWordHighlightingRule (
1103+ "[ERROR]" ,
1104+ ConsoleOutputColor . White ,
1105+ ConsoleOutputColor . Red
1106+ ) ,
1107+ new ConsoleWordHighlightingRule (
1108+ "[FATAL]" ,
1109+ ConsoleOutputColor . Black ,
1110+ ConsoleOutputColor . DarkRed
1111+ )
1112+ } ,
1113+ RowHighlightingRules =
1114+ {
1115+ new ConsoleRowHighlightingRule (
1116+ "level == LogLevel.Trace" ,
1117+ ConsoleOutputColor . Gray ,
1118+ ConsoleOutputColor . NoChange
1119+ ) ,
1120+ }
10681121 }
10691122 )
10701123 . WithAsync ( ) ;
0 commit comments