C#: > ps.Ru-6ren">
gpt4 book ai didi

c# - "Write-Error"(在 Powershell 中编写,在 C# 中使用)有效但 Write-Debug 不起作用 - 为什么?

转载 作者:可可西里 更新时间:2023-11-01 13:54:02 26 4
gpt4 key购买 nike

我用 C# 编写了一个程序,它创建了一个日志文件并使用 log4net 填充它。该程序启动 powershell-scripts。这些脚本也使用 log4net。有效:

> C#:   
> ps.Runspace.SessionStateProxy.SetVariable("myMethod",(Action<Level,string>)myMethod);
> ps.AddCommand(System.IO.Path.Combine(pathScripts, testSkripte[i].ToString()));
> ps.Invoke();

> Powershell:
> $ScriptLog.Invoke([log4net.Core.Level]::Debug, "TestFile_Debug")
> $ScriptLog.Invoke([log4net.Core.Level]::Warn, "TestFile_Warn") $ScriptLog
> $ScriptLog.Invoke([log4net.Core.Level]::Error, "TestFile_Error")

现在我想在我的脚本中添加使用标准的 Write-Error、Write-Debug 等 CMDlet。
(looks like here - Hinek 的回答)。

Powershell:
Write-Warning "Write-Warning"
AND
Write-Error "Write-Error"

有效,但以下无效:

Write-Debug "Write-Debug"         (I don´t get an item in my logfile)   OR    
Write-Debug "Write-Debug" -debug (for this I get an item in my logfile, but ...)

...我的日志文件中也出现错误。错误看起来像这样:

[2010-10-22 13:10:58,097] DEBUG : Write-Debug                                     
[2010-10-22 13:10:58,113] ERROR : Cannot invoke this function because the current
host does not implement it

(我想拥有所有的命名空间。)

错误消息是什么意思,我又该怎么做?

谢谢

最佳答案

消息“当前主机未实现它”告诉您应该提供一个实现遗漏功能的主机。据推测,您应该实现自己的 PSHostPSHostUserInterface,至少是您真正需要的。在后一类中,您可以实现 WriteDebugLineWriteErrorLine 等方法。然后 cmdlet Write-WarningWrite-Debug 在内部触发该方法。

具有用户界面和这些方法的主机的完整示例: http://msdn.microsoft.com/en-us/library/ee706577(v=VS.85).aspx(也许你不需要大多数其他方法,然后提供一些假人)

关于c# - "Write-Error"(在 Powershell 中编写,在 C# 中使用)有效但 Write-Debug 不起作用 - 为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3996958/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com