在Windows 2008服务器上拖尾日志文件

时间:2013-07-02 07:06:50

标签: windows powershell

我使用以下命令从windows8客户端pc上拖拽w2k8服务器上的日志文件:

get-content "file" -wait

日志文件显示出来并耐心地等待添加新行, 但是添加它们时,新行永远不会出现。

它在w2k3服务器上工作正常,但不知何故在w2k8服务器上拖尾不起作用。

日志文件从C#服务更新:

Trace.Listeners.Add(new TextWriterTraceListener(logFileName, "fileListener"));
Trace.WriteLine(....)

有人知道该怎么做吗?

1 个答案:

答案 0 :(得分:1)

我使用Trace类在我的WS08系统上重新编写了这个问题。我尝试了Trace.Flush()和编写大量数据(100K),但都没有导致get-content -wait响应。

但是我确实找到了解决方法。您必须更新您的C#程序。 (在进行实验时我得出的结论是gc -wait非常脆弱。)

$twtl= new-object diagnostics.TextWriterTraceListener "C:\temp\delme.trace",
                                                      "filelistener"
[diagnostics.trace]::Listeners.add($twtl)

# This sequence would result in gc -wait displaying output
[diagnostics.trace]::WriteLine("tracee messagee thingee")
[diagnostics.trace]::flush()
# Here I did file name completion such that c:\temp\delme.trace was in the 
#  completion list. 
# In other words I typed something like d and pressed tab
# And this worked every time 

# After searching for quite a while I finally found that 
#   get-itemproperty c:\temp\d*
# produced the same effect. The following sequence always worked:
# (without requiring a tab press)

[diagnostics.trace]::WriteLine("tracee messagee thingee")
[diagnostics.trace]::flush()
get-itemproperty c:\temp\d*

# To finish up
[diagnostics.trace]::Listeners.remove($twtl)
$twtl.close()
$twtl.dispose()

我认为某处有一个错误。我建议在Connect网站上提交。