在PowerShell中使用Nlog-Logger时禁用了残疾人

发布于 2025-01-22 06:13:11 字数 1307 浏览 0 评论 0原文

我的nlog.config

<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xsi:schemaLocation="NLog NLog.xsd"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      autoReload="true"
      internalLogFile="c:\temp\console-example-internal.log"
      internalLogLevel="Info" >

    <!-- the targets to write to -->
    <targets>
        <target xsi:type="File" name="logfile" fileName="c:\temp\console-example.log"
                layout="${shortdate} | ${level} | ${callsite} | ${message} | ${all-event-properties} ${exception:format=tostring}" />
        <target xsi:type="Console" name="logconsole"
                layout="${shortdate} | ${level} | ${callsite} | ${message} | ${all-event-properties} ${exception:format=tostring}" />
    </targets>

    <!-- rules to map from logger name to target -->
    <rules>
        <logger name="*" minlevel="Trace" writeTo="logfile,logconsole" />
    </rules>
</nlog>

“在此处输入图像描述”

当我在powerShell中导入nlog.dll时,从logmanager.getCurrentCrastLogger()禁用了logmanager.getCurrentClassLogger()。因此我无法记录。

My nlog.config

<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xsi:schemaLocation="NLog NLog.xsd"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      autoReload="true"
      internalLogFile="c:\temp\console-example-internal.log"
      internalLogLevel="Info" >

    <!-- the targets to write to -->
    <targets>
        <target xsi:type="File" name="logfile" fileName="c:\temp\console-example.log"
                layout="${shortdate} | ${level} | ${callsite} | ${message} | ${all-event-properties} ${exception:format=tostring}" />
        <target xsi:type="Console" name="logconsole"
                layout="${shortdate} | ${level} | ${callsite} | ${message} | ${all-event-properties} ${exception:format=tostring}" />
    </targets>

    <!-- rules to map from logger name to target -->
    <rules>
        <logger name="*" minlevel="Trace" writeTo="logfile,logconsole" />
    </rules>
</nlog>

enter image description here

When i import the Nlog.dll in PowerShell the logger from LogManager.GetCurrentClassLogger() is disabled. Therefore i can't log.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

找回味觉 2025-01-29 06:13:11

在PowerShell中,必须手动设置nlog.config。
https://github.github.github.com/rafpe/rrafpe/953838c51Edb7fb7efb7efb7efb7efb7efb7f43c4

$xmlConfig = New-Object NLog.Config.XmlLoggingConfiguration("\\pathToConfig\NLog.config")
[NLog.LogManager]::Configuration = $xmlConfig
    
# Create logger 
$logger = [NLog.LogManager]::GetLogger('logger.name')

In PowerShell one has to set the nlog.config manually.
https://gist.github.com/RafPe/95ef838c51edb7ef43c4

$xmlConfig = New-Object NLog.Config.XmlLoggingConfiguration("\\pathToConfig\NLog.config")
[NLog.LogManager]::Configuration = $xmlConfig
    
# Create logger 
$logger = [NLog.LogManager]::GetLogger('logger.name')
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文