C# 将日志文件输出到WPF列表框
我想在我的C# 将日志文件输出到WPF列表框,c#,wpf,C#,Wpf,我想在我的WPF应用程序的列表框中显示我的日志文件。我已经修改了示例应用程序来做到这一点。但是,我有一个关于显示文件内容的问题 void DisplayFileSystemWatcherInfo(System.IO.WatcherChangeTypes watcherChangeTypes, string name, string oldName = null) { Dispatcher.BeginInvoke(new Action(() => { AddListLine(stri
WPF应用程序的列表框中显示我的日志文件。我已经修改了示例应用程序来做到这一点。但是,我有一个关于显示文件内容的问题
void DisplayFileSystemWatcherInfo(System.IO.WatcherChangeTypes watcherChangeTypes, string name, string oldName = null)
{
Dispatcher.BeginInvoke(new Action(() => { AddListLine(string.Format("{0} -> {1} - {2}", watcherChangeTypes.ToString(), name, DateTime.Now)); }));
}
它仅在文件发生更改时打印。我希望将日志文件的内容显示在屏幕上。如何做到这一点?您现在拥有的是一种监视文件中的更改并将这些更改添加到列表框的方法
如果要读取文件并将其内容添加到列表框。
下面是其中的一个代码示例:
listboxObject.DataSource = File.ReadAllLines("PathToYourFileHere");
将列表框替换为
<TextBox Height="300" HorizontalAlignment="Left" Name="txtContent"
VerticalAlignment="Top" Width="549" IsReadOnly="True" Text="" AcceptReturn="True"></TextBox>
AddListLine做什么?
void DisplayFileSystemWatcherInfo(System.IO.WatcherChangeTypes watcherChangeTypes, string name, string oldName = null)
{
Dispatcher.BeginInvoke(new Action(() => { txtContent.Text= System.IO.File.ReadAllText("filePath"); }));
}