将输出窗口重定向到日志文件
|
当我的应用程序启动时,我看到以下行被写入输出窗口:
\'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()方法。有任何想法吗?
没有找到相关结果
已邀请:
3 个回复
诫商
橙绥
倾坞髓
事件。最简单的例子是:
这不会捕获您所需要的所有内容,也不会提供与Visual Studio输出窗口完全相同的格式,但是这可能是一个可以接受的“半途而废”的东西。