我正在使用滚动文件接收器。
以下是我的初始化代码:
Serilog.Log.Logger = new LoggerConfiguration()
.WriteTo.RollingFile(@"L:\logs\Api-{Date}.txt", fileSizeLimitBytes: null)
.CreateLogger();
这是要记录的行:
Log.Information(message);
但在 2 KB 之后,它会创建一个新文件。
我不知道出了什么问题。
更新
这是我的记录器类:
public class Logger
{
public Logger()
{
Serilog.Log.Logger = new LoggerConfiguration()
.MinimumLevel.Verbose()
.WriteTo.RollingFile(@"L:\logs\Api-{Date}.txt", fileSizeLimitBytes: null)
.CreateLogger();
}
public void Log(LogRequestParameters logRequestParameters, LoggingLevels loggingLevel)
{
var message = JsonConvert.SerializeObject(logRequestParameters);
switch (loggingLevel)
{
case LoggingLevels.Verbose:
Serilog.Log.Verbose(message);
break;
case LoggingLevels.Debug:
Serilog.Log.Debug(message);
break;
case LoggingLevels.Information:
Serilog.Log.Information(message);
break;
case LoggingLevels.Warning:
Serilog.Log.Warning(message);
break;
case LoggingLevels.Error:
Serilog.Log.Warning(message);
break;
case LoggingLevels.Fatal:
Serilog.Log.Fatal(message);
break;
}
}
}
这是我的调用者类:
public class Caller
{
logRequestParameters.DateTime = DateTime.Now.ToString();
logRequestParameters.Level = "Debug";
logRequestParameters.MachineName = Environment.MachineName;
logRequestParameters.Type = "Request";
logRequestParameters.Request = request;
Logger logger = new Logger();
logger.Log(logRequestParameters, LoggingLevels.Information);
}