Skip to content

Commit

Permalink
chore: update logger
Browse files Browse the repository at this point in the history
  • Loading branch information
GZTimeWalker committed Nov 8, 2022
1 parent ff28056 commit cb3c40f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
4 changes: 1 addition & 3 deletions GZCTF/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@
builder.Configuration.AddEnvironmentVariables("GZCTF_");
Log.Logger = LogHelper.GetInitLogger();

Log.Logger.Debug("GZCTF 正在启动中……");

#endregion Logging

#region AppDbContext
Expand Down Expand Up @@ -130,7 +128,7 @@

#region Cache

if (string.IsNullOrWhiteSpace(builder.Configuration.GetConnectionString("RedisCache")))
if(!builder.Configuration.GetSection("ConnectionStrings").GetSection("RedisCache").Exists())
{
builder.Services.AddDistributedMemoryCache();
}
Expand Down
3 changes: 2 additions & 1 deletion GZCTF/Utils/LogHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ public static void Log<T>(this ILogger<T> _logger, string msg, string uname, str
};

private const string LogTemplate = "[{@t:yy-MM-dd HH:mm:ss.fff} {@l:u3}] {Substring(SourceContext, LastIndexOf(SourceContext, '.') + 1)}: {@m} {#if Length(Status) > 0}#{Status} <{UserName}>{#if Length(IP) > 0}@{IP}{#end}{#end}\n{@x}";
private const string InitLogTemplate = "[{@t:yy-MM-dd HH:mm:ss.fff} {@l:u3}] {@m}\n{@x}";

public static Logger GetInitLogger()
=> new LoggerConfiguration()
Expand All @@ -105,7 +106,7 @@ public static Logger GetInitLogger()
.MinimumLevel.Override("Microsoft.Hosting.Lifetime", LogEventLevel.Information)
.MinimumLevel.Override("Microsoft.Hosting.Lifetime", LogEventLevel.Warning)
.WriteTo.Async(t => t.Console(
formatter: new ExpressionTemplate(LogTemplate, theme: TemplateTheme.Literate),
formatter: new ExpressionTemplate(InitLogTemplate, theme: TemplateTheme.Literate),
restrictedToMinimumLevel: LogEventLevel.Debug
))
.CreateLogger();
Expand Down

0 comments on commit cb3c40f

Please sign in to comment.