[英]C# How to save Console.Writeline Outputs to HTML Format?
我有一个程序,可以从日志文本文件中提取字符串后输出各种结果。 结果显示在命令行控制台上。
因此,是否有将各种输出结果生成为基于html的报告的方法?
可以使用哪些方法转换输出? HtmlTextWriter? 转换文件需要什么步骤?
有人可以建议这样做吗? 谢谢!
代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.IO;
using System.Text.RegularExpressions;
using System.Web.UI; // The system is telling me that it does not exist in the namespace System.web....
foreach (String r in lines.Skip(1))
{
String[] token = r.Split(',');
String[] datetime = token[0].Split(' ');
String timeText = datetime[4];
Double rawSize = Convert.ToDouble(token[1]);
Double fileSize = ((rawSize / 1024) / 1024);
String actions = token[2];
String fileName = token[7];
if ((Path.GetExtension(token[7]).Contains(".exe") || (Path.GetExtension(token[7]).Contains(".msi"))))
{
Console.WriteLine("The time for this array is: " + timeText);
Console.WriteLine(token[7]);
Console.WriteLine(actions);
Console.WriteLine(fileSize);
ProgramFilter(actions, k, fileName);
x = 1;
Console.WriteLine("================================================");
}
}
HTML是基于文本的格式,因此您可以简单地输出HTML。
没有什么可以简单地将文本转换为HTML的-您需要确定标记是什么。
有很多选项可以做到这一点:
至于写入文件-再次,有几种方法可以做到这一点:
File
类 FileStream
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.