我想知道是否有可能实现过滤,我们改进对 serilog 的过滤,使其对子记录器更加具体。目前我可以过滤命名空间,但是我只想访问特定命名空间中的一种方法来记录到电子邮件,该命名空间的其余方法应保留默认日志记录。
.Filter.ByIncludingOnly(Matching.FromSource("SomeNamespace"))
Run Code Online (Sandbox Code Playgroud)
但是,我只想访问 SomeNamespace 中的 method1,而不是访问也位于同一命名空间中的 method2。有任何想法吗?
我无法使用 Serilog 级别来实现此目的。最想要的是过滤器的使用。
我想用一些自定义信息(例如用户角色、业务解决方案......)来丰富 serilog 跟踪消息,并且我希望在 Application Insight“自定义维度”字段中看到这些属性。我试图环顾四周,但没有找到合适的解决方案。我正在使用 ASP.NET Core 3.1
logging serilog azure-application-insights .net-5 asp.net-core-3.1
我有一个具有多个线程的 .Net Worker Service 应用程序。我想将每个线程记录到单独的文件中,以便更轻松地阅读日志。有什么想法来实现这个吗?
我正在尝试使用 Serilog 登录我的 ASP.NET Web API 项目之一中的 Elasticsearch,但不幸的是,我在 Kibana 中找不到日志。
public class Logger
{
private readonly ILogger _localLogger;
public Logger()
{
ElasticsearchSinkOptions options = new ElasticsearchSinkOptions(new Uri("xxx"))
{
IndexFormat = "log-myservice-dev",
AutoRegisterTemplate = true,
ModifyConnectionSettings = (c) => c.BasicAuthentication("yyy", "zzz"),
NumberOfShards = 2,
NumberOfReplicas = 0
};
_localLogger = new LoggerConfiguration()
.MinimumLevel.Information()
.WriteTo.File(HttpContext.Current.Server.MapPath("~/logs/log-.txt"), rollingInterval: RollingInterval.Day)
.WriteTo.Elasticsearch(options)
.CreateLogger();
}
public void LogError(string error)
{
_localLogger.Error(error);
}
public void LogInformation(string information)
{
_localLogger.Information(information);
}
}
Run Code Online (Sandbox Code Playgroud)
我可以在上面指定的文件中看到日志,但在 Elasticsearch 中看不到。所以,我想知道是否有什么方法可以调试为什么无法登录 Elasticsearch?我也愿意使用其他日志框架来登录 Elasticsearch。
*Elasticsearch 的凭证和 …
我的问题是,当涉及到源代码时,我需要对 Serilog MinimumLevel.Override 进行多细化?
例如,我希望将来自 Microsoft 的所有消息都记录在警告级别。
来源“Microsoft”是否足够?
.MinimumLevel.Override("Microsoft", LogEventLevel.Warning)
Run Code Online (Sandbox Code Playgroud)
或者我需要做这样的事情:
.MinimumLevel.Override("Microsoft", LogEventLevel.Warning)
.MinimumLevel.Override("Microsoft.AspNetCore", LogEventLevel.Warning)
....
Run Code Online (Sandbox Code Playgroud) 我想使用Serilog登录.Net core 2.0类库项目.我搜索了很多地方,没有找到任何将Serilog集成到类库项目中的示例.有人可以参考样品吗?
谢谢.
如何排除 xml 配置文件中的列?
我想做这个 serilogColumnOptions.Store.Remove(StandardColumn.Properties); 配置文件中的事件
尽管在谷歌上花了几个小时,但我还是没有到达那里。我们有一个 Core 3.1 MVC Web App 项目,我被要求使用 SeriLog 将日志写入 Azure 表存储。对于我的一生,我无法在网上找到有效的示例或教程。这是我到目前为止所做的:
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Information",
"Microsoft.Hosting.Lifetime": "Warning"
}
Run Code Online (Sandbox Code Playgroud)
有了这个:
"Serilog": {
"WriteTo": [
{
"Name": "AzureTableStorage",
"Args": {
"storageTableName": "Logs",
"connectionString": "DefaultEndpointsProtocol=https;AccountName=***;AccountKey=***;EndpointSuffix=core.windows.net"
}
}
]
},
Run Code Online (Sandbox Code Playgroud)
现在我被困住了。目前Program.cs位于CreateHostBuilder:
.ConfigureLogging(logging =>
{
logging.AddConsole();
})
Run Code Online (Sandbox Code Playgroud)
我想我应该更换这个?但是,用什么?我不知道从这里该去哪里。Github 上的serilog -sinks-azuretablestorage页面没有太大帮助。我无法通过谷歌找到任何解释如何完成实施的内容。
我们正在使用下面的一段 serilog 代码,它将事件写入控制台和文件,文件和控制台日志记录在我的机器上工作正常,但在其他开发人员机器上控制台日志记录工作,但文件日志记录不起作用,这增加了奇怪之处不过,“logs”文件夹已创建。是否需要进行任何额外的设置?
public static void SetupLogger()
{
//var outputTemplate = "[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj}{NewLine}{Exception}";
var outputTemplate = "[{Level:u3}] {Message:lj}{NewLine}{Exception}";
// Logger
//var outputTemplate = "{Timestamp:yyyy-MM-dd HH:mm:ss.fff} [{Level:u4}] | {Message:l}{NewLine}{Exception}";
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Verbose()
.WriteTo.Console(outputTemplate: outputTemplate, theme:SystemConsoleTheme.Literate,restrictedToMinimumLevel:LogEventLevel.Information)
.WriteTo.File($"logs/log-{DateTime.Now:yyyy-MM-dd_HH:mm:ss.fff}.log")
.CreateLogger();
}
Run Code Online (Sandbox Code Playgroud) 我有 azure webjob sdk (v3.0.3) 应用程序,已配置为使用 serilog 进行日志记录。当我在系统中本地运行该应用程序时,该日志似乎有效。下面是配置:
static void Main(string[] args)
{
try
{
var builder = new HostBuilder()
.ConfigureAppConfiguration(SetupConfiguration)
.ConfigureLogging(SetupLogging)
.ConfigureServices(SetupServices)
.ConfigureWebJobs(webJobConfiguration =>
{
webJobConfiguration.AddTimers();
webJobConfiguration.AddAzureStorageCoreServices(); //this is to store logs in azure storage
})
.UseSerilog()
.Build();
builder.Run();
}
}
Run Code Online (Sandbox Code Playgroud)
设置配置的代码如下:
private static void SetupConfiguration(HostBuilderContext hostingContext, IConfigurationBuilder builder)
{
var env = hostingContext.HostingEnvironment;
_configuration = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: false, reloadOnChange: true)
.AddEnvironmentVariables()
.Build();
}
Run Code Online (Sandbox Code Playgroud)
设置服务的代码:
private static void SetupServices(HostBuilderContext hostingContext, IServiceCollection …Run Code Online (Sandbox Code Playgroud) logging azure serilog azure-webjobssdk azure-webjobs-continuous