程序中使用RemoteLog
约 206 字小于 1 分钟
2025-02-12
在appsettings.json文件中,设置日志服务器url
"Logging": {
"ServerUrl": "http://127.0.0.1:9000",//日志服务器地址
"ContextName": "YourContextName", //程序名称
"LogLevel": {
"Default": "Debug",
"Microsoft.AspNetCore": "Warning"
},
"Console": {
"LogLevel": {
"Default": "Information"
}
}
}
在工程中引用 nuget 包:Jack.RemoteLog
注册 Jack.RemoteLog 为底层日志处理引擎
services.AddLogging(builder =>
{
builder.AddConfiguration(configuration.GetSection("Logging"));
builder.AddConsole();
builder.UseJackRemoteLogger(configuration);
});
如果 RemoteLog 服务器端设置了身份验证,则这里需要设置用户名、密码:
services.AddLogging(builder =>
{
builder.AddConfiguration(configuration.GetSection("Logging"));
builder.AddConsole();
builder.UseJackRemoteLogger(configuration , new Options
{
UserName = "",
Password = ""
});
});
当您使用 ILogger 接口实例来记录信息时,该信息将被记录到日志服务器。
而要查看服务器上的所有日志,您可以通过浏览器打开 http://127.0.0.1:9000,然后可以轻松地获取你的程序日志以进行监视和分析。