TTC*_*TCG 7 logging asp.net-core-mvc asp.net-core
我曾经使用 DebugView.exe 在经典 ASP.Net 中查看来自我的 Web 应用程序的调试消息。我只需要使用 Debug.WriteLine("要显示的消息"); 它显示在 DebugView 的窗口中。我还可以使用该方法跟踪/查看生产服务器上的消息。
例如。http://woutercx.com/2013/08/23/debugview-tool-how-it-saved-my-day/
在 ASPNetCore 中,我尝试使用记录器来做同样的事情。我可以在 VS2015 输出窗口中正确查看所有日志记录。但我在 DebugView 软件中再也看不到它了。这些日志消息与来自 MVC 和 ASP 引擎的其他数千条日志行一起丢失,并且很难查看我只想查看的消息。
请参见下图中的示例:
是否有办法在 ASP.Net Core 的 DebugView 中查看这些日志消息?或者无论如何要摆脱 ASPNet.Core 中的那些额外日志记录?
我确实尝试排除 Startup.cs 中的这些行...但尚未成功。
loggerFactory.AddConsole((cat, level) => cat.StartsWith("WindowsAuthentication.") && level == LogLevel.Debug);
loggerFactory.AddDebug(LogLevel.Debug);
Run Code Online (Sandbox Code Playgroud)
看起来源仅Debug.WriteLine在附加调试器时调用,这意味着它在生产中是无操作的(除非您使用附加的调试器进行远程调试)。请参阅 GitHub 上的相关源代码行:https://github.com/aspnet/Logging/blob/master/src/Microsoft.Extensions.Logging.Debug/DebugLogger.cs#L48-L50。它说:
public bool IsEnabled(LogLevel logLevel)
{
// If the filter is null, everything is enabled
// unless the debugger is not attached
return Debugger.IsAttached &&
logLevel != LogLevel.None &&
(_filter == null || _filter(_name, logLevel));
}
Run Code Online (Sandbox Code Playgroud)
我怀疑您可以编写自己的调试记录器提供程序,它看起来与 GitHub 中的内容几乎相同,但方法忽略IsEnabled检查Debugger.IsAttached。
| 归档时间: |
|
| 查看次数: |
1333 次 |
| 最近记录: |