File tree Expand file tree Collapse file tree
GameFrameX.Foundation.Logger Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -90,20 +90,21 @@ public static LoggerConfiguration CreateLoggerConfiguration()
9090 public static ILogger Create ( LogOptions logOptions , bool isDefault = true , Action < LoggerConfiguration > configurationAction = null )
9191 {
9292 ArgumentNullException . ThrowIfNull ( logOptions ) ;
93- ArgumentException . ThrowIfNullOrWhiteSpace ( logOptions . LogTagName , nameof ( logOptions . LogTagName ) ) ;
93+ ArgumentException . ThrowIfNullOrWhiteSpace ( logOptions . LogType , nameof ( logOptions . LogType ) ) ;
9494 SerilogDiagnosis ( ) ;
9595 try
9696 {
9797 // 文件名
98- var logFileName = $ "{ logOptions . LogTagName } _.log";
99- // 日志文件存储的路径
98+ var logFileName = logOptions . LogFileName . IsNotNullOrEmptyOrWhiteSpace ( ) ? logOptions . LogFileName : $ "{ logOptions . LogTagName ?? logOptions . LogType } _.log";
99+
100+ // 日志文件存储的路径,默认在应用程序运行目录下的子目录/logs
100101 var logSavePath = logOptions . LogSavePath ?? "./logs/" ;
101102 if ( ! logSavePath . EndsWith ( Path . DirectorySeparatorChar ) )
102103 {
103104 logSavePath += Path . DirectorySeparatorChar ;
104105 }
105106
106- logSavePath += logOptions . LogTagName + Path . DirectorySeparatorChar ;
107+ logSavePath += logOptions . LogType + Path . DirectorySeparatorChar ;
107108
108109 // 计算最终日志文件路径
109110 var logPath = Path . Combine ( logSavePath , logFileName ) ;
Original file line number Diff line number Diff line change @@ -39,6 +39,14 @@ public LogOptions(string logPathName = "logs")
3939 /// </summary>
4040 public bool IsWriteToFile { get ; set ; } = true ;
4141
42+ /// <summary>
43+ /// 服务器类型,用于标识日志来源的服务器类型。
44+ /// </summary>
45+ /// <remarks>
46+ /// 可以用来区分不同服务器产生的日志,便于日志的分类和管理。
47+ /// </remarks>
48+ public string LogType { get ; set ; }
49+
4250 /// <summary>
4351 /// 日志标签名,用于标识日志的名称或描述。
4452 /// </summary>
@@ -97,6 +105,11 @@ public LogOptions(string logPathName = "logs")
97105 /// </remarks>
98106 public string LogSavePath { get ; private set ; }
99107
108+ /// <summary>
109+ /// 日志文件名,为空时使用默认名称。
110+ /// </summary>
111+ public string LogFileName { get ; set ; } = string . Empty ;
112+
100113 /// <summary>
101114 /// 是否输出到控制台,默认为 true。
102115 /// </summary>
You can’t perform that action at this time.
0 commit comments