Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/272.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在为webservice配置的nlog.config文件中是否缺少用于在控制器中触发方法的设置?_C#_Web Services_Nlog_Nlog Configuration - Fatal编程技术网

C# 在为webservice配置的nlog.config文件中是否缺少用于在控制器中触发方法的设置?

C# 在为webservice配置的nlog.config文件中是否缺少用于在控制器中触发方法的设置?,c#,web-services,nlog,nlog-configuration,C#,Web Services,Nlog,Nlog Configuration,我想将信息从Nlog发送到一个文件中,同时发送到一个Web服务。 这个文件很好用。 webservice one不会在控制器上遇到断点 我尝试了此处、此处推荐的步骤,并理解这应该是可行的,因为我使用了以下检测记录器的代码: 测试工作正常: DebugTarget target = new DebugTarget(); target.Layout = "${message}"; NLog.Config.SimpleConfigurator.ConfigureForTarge

我想将信息从Nlog发送到一个文件中,同时发送到一个Web服务。 这个文件很好用。 webservice one不会在控制器上遇到断点

我尝试了此处、此处推荐的步骤,并理解这应该是可行的,因为我使用了以下检测记录器的代码:

测试工作正常:

    DebugTarget target = new DebugTarget();
    target.Layout = "${message}";
    NLog.Config.SimpleConfigurator.ConfigureForTargetLogging(target, LogLevel.Debug);
    Logger logger = LogManager.GetLogger("ws");
    logger.Debug("log message"); <--- here I expected to hit the breakpoint after this step
    logger.Debug("another log message");

我希望在NlogController中点击断点,查看内部数据。

在找到具有相同错误的人后,我发现了错误

第一个错误是:

protected new static readonly Logger Logger = LogManager.GetCurrentClassLogger();
使用时

    <logger name="ws" minlevel="Trace" writeTo="ws"/>
之后,出现了第二个错误

url= 'http://localhost:8082/API/Nlog'
url= 'http://localhost:Port/{Path}/Controller**/Action**' is the correct syntax. 
在这两次改变之后,我可以达到我的断点,一切都按预期进行! 谢谢你的帮助


我希望Nlog团队能够改变这一点

配置示例:

<nlog>
<targets>
    <target type='WebService'
            name='ws'
            url='http://localhost:1234/logme' <-- change to 'http://localhost:1234/logme/Post'
            protocol='HttpPost'
            encoding='UTF-8'   >
        <parameter name='param1' type='System.String' layout='${message}'/> 
        <parameter name='param2' type='System.String' layout='${level}'/>
    </target>
</targets>
<rules>
  <logger name='*' writeTo='ws'></logger>
</rules>
</nlog>

将节省2天的工作。

您是否检查了NLog InternalLogger-中的错误?你试过使用像Fiddler这样的工具来检查实际的http请求吗?谢谢,我两者都用过。Fiddler没有发现任何令我惊讶的请求。内部记录器抛出未为记录器配置的调试目标。而且所有目标都是空的……但他设法找到了ws和文件目标。跟踪关闭WebService目标[ws]调试关闭目标“WebService目标[ws]”。调试关闭的目标“WebService目标[ws]”。跟踪关闭文件目标[文件]调试关闭目标“文件目标[文件]”。已关闭目标“文件目标[文件]”。无错误您可以更改asp net mvc with c使用方法名并将其添加到URL(如soap)中,或者更改示例,并提示URL中需要执行该操作。我希望Nlog团队在此时更改该操作。维基是可公开编辑的;谢谢,但由于我不知道他们推荐哪种修复方法,或者是否计划使用methodName选项,所以我让它使用them@Lukas为您更新了Wiki示例:
    <logger name="ws" minlevel="Trace" writeTo="ws"/>
Logger logger = LogManager.GetLogger("ws");
url= 'http://localhost:8082/API/Nlog'
url= 'http://localhost:Port/{Path}/Controller**/Action**' is the correct syntax. 
<nlog>
<targets>
    <target type='WebService'
            name='ws'
            url='http://localhost:1234/logme' <-- change to 'http://localhost:1234/logme/Post'
            protocol='HttpPost'
            encoding='UTF-8'   >
        <parameter name='param1' type='System.String' layout='${message}'/> 
        <parameter name='param2' type='System.String' layout='${level}'/>
    </target>
</targets>
<rules>
  <logger name='*' writeTo='ws'></logger>
</rules>
</nlog>