- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有这个程序
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
namespace debuglogtest
{
public class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureServices((hostContext, services) =>
{
services.AddHostedService<Worker>();
});
}
}
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
namespace debuglogtest
{
public class Worker : BackgroundService
{
private readonly ILogger<Worker> _logger;
public Worker(ILogger<Worker> logger)
{
_logger = logger;
}
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
_logger.LogDebug("_logger.LogDebug");
_logger.LogTrace("_logger.LogTrace");
Debug.WriteLine("Debug.WriteLine");
}
}
}
{
"Logging": {
"LogLevel": {
"Default": "Debug",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
}
}
dotnet run -c Debug
我在控制台中得到了这个
dbug: debuglogtest.Worker[0] _logger.LogDebug
dotnet run -c Release
在发行版中编译它时我仍然在控制台中得到这个
dbug: debuglogtest.Worker[0] _logger.LogDebug
_logger.LogDebug
在debug中编译时在console和DebugView中都写,在Release中编译时没有地方Debug.WriteLine
在调试中编译时在 DebugView 中编写 _logger.LogDebug
仅写入控制台,而不是 Debug模式下的 DebugView Debug.WriteLine
只有在 Debug模式下编译时才能正确写入。
LogDebug
正在调用
Debug.WriteLine
在引擎盖下,但也许
Debug.WriteLine
和
Logger.LogDebug
是两个不同的东西吗?我肯定看起来像。我认为这很令人困惑,因为我们需要在两个不同的地方(编译和过滤时)控制调试日志记录。如果我阅读文档:
https://docs.microsoft.com/en-us/aspnet/core/fundamentals/logging/?view=aspnetcore-3.1#debug它说它调用相同的
Debug.WriteLine
:
The Debug provider writes log output by using the System.Diagnostics.Debug class. Calls to System.Diagnostics.Debug.WriteLine write to the Debug provider.
Logger.Debug
在 Debug模式下编译时。那不可能吗?
#define DEBUG
,并调用
Debug.WriteLine
,但它并没有在我的脑海中加起来。它应该会出现在 DebugView 中,但它不会同时出现在调试和 Release模式中。
最佳答案
ILogger.LogDebug
, ILogger.LogTrace
等等是关于 LogLevel
消息而不是关于它写在哪里,基本上相当于调用 Log(..)
对应值 logLevel
范围。日志消息的写入目的地由您使用的记录器决定(控制台、文件、ETW,我相信您甚至可以创建一个写入调试 View 的记录器,请参阅文档的 logging providers section)。 LogLevel
允许您过滤实际写入日志目标的日志级别,并由 appsettings 而非构建配置直接管理(尽管您可以为不同的配置设置不同的设置)。
关于c# - Logger.LogDebug 与 Debug.WriteLine,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62121673/
Console.WriteLine() 和有什么区别和Trace.WriteLine() ? 最佳答案 从“调试”的角度来看这些。 我们开始使用 Console.WriteLine() 进行调试 后来
Console.WriteLine() 与 Debug 之间有什么区别.WriteLine()? 最佳答案 Console.WriteLine在调试或发布中写入标准输出流。 Debug.WriteLi
由于这里的用户,我最近来到了 log4net。无论如何,我想将每个 Console.Write() 和 Debug.Write() 自动记录到我配置的单个日志文件中。此外,我使用了许多类库,这些类库也
webjob 的方法可以使用 TextWriter logger 作为参数。但如果我打电话: logger.WriteLine("Test"); Console.WriteLine("Test");
我有一些代码需要在运行测试时查看,并且TestContext 必须是我的测试类的一部分我需要显示正在测试的类的 debug.writelines。我考虑过只是将 TestContext 传递给我的 M
在我们的一个应用程序中,我遇到过这样的行: Console.WriteLine(string.Empty); 我检查了如果我只写它是否有任何不同: Console.WriteLine(); 但输出是相
考虑以下控制台应用程序代码: Thread.CurrentThread.CurrentCulture = new CultureInfo("en-GB"); Thread.CurrentThread.
我完全是 C# 的菜鸟和初级程序员,但我在阅读有关 Roslyn 和“C# 7.0 的新增功能”的文章时发现了一些非常有趣的东西,但我找不到我需要的答案。 在此link ,所有给出的示例都包含类似 W
哪个更快?哪个占用的内存更少? Console.WriteLine("string1") Console.WriteLine("string2") Console.WriteLine("string3
Afileobject f 具有以下 IO 方法,根据 Python in a Nutshell: f.read(size=-1) In v2, or in v3 when f is open in
为什么 Visual Studio 抛出错误 Console.WriteLine('string with single quote'); 而不是: Console.WriteLine("string
很难说出这里要问什么。这个问题模棱两可、含糊不清、不完整、过于宽泛或夸夸其谈,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开,visit the help center . 关闭 1
我依稀记得在 nUnit 中可能在 reSharper 或 TeamCity 的上下文中阅读了关于在 Console.Out.WriteLine 上使用 Trace.WriteLine 的“某事”“某
在我的 C# 代码中,我想将 Debug.WriteLine() 和 Console.WriteLine() 包装到一个函数中,以便它在调试时以调试窗口为目标模式和控制台处于 Release模式。实现
我正在制作一个 SchoolApp 程序来学习 C#,我有一个我正在努力实现的主要功能: namespace SchoolApp { class Program { p
我有一个日志文件 (.txt),其中包含以下信息: Filename1 - A3332NCDER Filename2 - B3332NCDER Filename3 - B1222NCDERE F
是否可以编写一个循环,将重叠文本写入控制台? 期望的输出: 注意线条是如何重叠的。我在用'|'垂直和'-'水平。 垂直线是第 4 列,水平线是第 3 行。 我知道这离我们很远: for (int i
这是我的代码: static void Main(string[] args) { if(args.Length > 1) { int id; if(i
为什么我们不能在 C# 中的 if 条件中编写 Console.Writeline()?但是我们可以写printf() if 条件 C 中的语句? 最佳答案 在 C 中,printf 的返回类型是 i
我对 VBA 相当陌生,并且对如何解决执行此代码时收到的“运行时错误'5':无效的过程调用或参数”错误感到困惑。有问题的单元格有中文字符,代码似乎在英文字母上运行良好。流正在输出到文本文件。 (将来应
我是一名优秀的程序员,十分优秀!