当我的应用程序启动时,我看到以下行被写入输出窗口:
'MyApp.exe' (Managed (v2.0.50727)): Loaded 'C:\WINDOWS\assembly\GAC_MSIL\PresentationFramework.Luna\3.0.0.0__31bf3856ad364e35\PresentationFramework.Luna.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'MyApp.exe' (Managed (v2.0.50727)): Loaded 'C:\WINDOWS\assembly\GAC_MSIL\PresentationFramework.Aero\3.0.0.0__31bf3856ad364e35\PresentationFramework.Aero.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'MyApp.exe' (Managed (v2.0.50727)): Loaded 'C:\WINDOWS\assembly\GAC_MSIL\PresentationFramework.resources\3.0.0.0_nl_31bf3856ad364e35\PresentationFramework.resources.dll'
'MyApp.exe' (Managed (v2.0.50727)): Loaded 'C:\WINDOWS\assembly\GAC_MSIL\System.Data.SqlServerCe\3.5.1.0__89845dcd8080cc91\System.Data.SqlServerCe.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'MyApp.exe' (Managed (v2.0.50727)): Loaded 'C:\WINDOWS\assembly\GAC_32\System.Transactions\2.0.0.0__b77a5c561934e089\System.Transactions.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'MyApp.exe' (Managed (v2.0.50727)): Loaded 'C:\WINDOWS\assembly\GAC_32\System.EnterpriseServices\2.0.0.0__b03f5f7f11d50a3a\System.EnterpriseServices.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'MyApp.exe' (Managed (v2.0.50727)): Loaded 'C:\WINDOWS\assembly\GAC_MSIL\System.Data.resources\2.0.0.0_nl_b77a5c561934e089\System.Data.resources.dll'
'MyApp.exe' (Managed (v2.0.50727)): Loaded 'C:\WINDOWS\assembly\GAC_MSIL\System.Xml.Linq\3.5.0.0__b77a5c561934e089\System.Xml.Linq.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'MyApp.exe' (Managed (v2.0.50727)): Loaded 'Anonymously Hosted DynamicMethods Assembly'
我喜欢将这些行添加到我的日志文件中(并为一些性能测量指定时间戳)。我试着用我创建的以下课程来做到这一点。
public static class ConsoleLogger
{
public class LogWriter : TextWriter
{
public LogWriter()
{
}
public override Encoding Encoding
{
get { return Encoding.UTF8; }
}
public override void Write(string value)
{
Logger.Info(value);
}
}
public static void RedirectConsoleLog()
{
Console.SetOut(new LogWriter());
}
}
但这不起作用。永远不会调用Write()方法。有什么想法吗?
答案 0 :(得分:2)
您可以在Visual Studio中使用DebugView或File-> SaveoutputAs
答案 1 :(得分:2)
这些行由调试器生成。 this SDK article中记录了调试程序可以生成的通知类型。 DLL加载通知对应于事件6,LOAD_DLL_DEBUG_EVENT。当您右键单击“输出”窗口时,该列表几乎与您在上下文菜单中找到的内容相对应。您感兴趣的“模块加载消息”。
这有几个含义。首先,只有调试器可以获得这些通知,您通常在部署之后运行没有一个程序。 Windows中的一个严格限制是调试器必须是一个单独的进程,程序无法自行调试。您计划的最后一点是IDE不支持将现在发送到“输出”窗口的内容重定向到文件中。
除非您编写自己的调试器,否则无法完成此工作。从技术上讲,可以下载MDbg sample。实际上没有。
答案 2 :(得分:0)
您最接近的是处理AppDomain.AssemblyLoad
事件。最简单的例子是:
using System;
namespace ConsoleApplicationN
{
class Program
{
{
AppDomain.CurrentDomain.AssemblyLoad += new AssemblyLoadEventHandler(CurrentDomain_AssemblyLoad);
// You need to *DO* something here to trigger an assembly load
// For example, open a database connection
}
static void CurrentDomain_AssemblyLoad(object sender, AssemblyLoadEventArgs args)
{
// This is just an example of how to use what's provided in "args"
Console.WriteLine(args.LoadedAssembly.FullName);
}
}
}
这不会捕获您所追踪的所有内容,也不会提供与Visual Studio输出窗口完全相同的格式,但可能可能是之间可接受的“中途”房子。什么都没有。