私は IIS 10 を使用しており、.NET 4.5.2 WebSocket を出入りするトラフィックを追跡する必要があります。これは、誰かがサーバーに対して websocket を開いたときに作成されますが、これはまったく不可能のようです。
現在のトレース構成は、System.Net、System.Net.Http、System.Net.Sockets、および System.Net.WebSockets を記録しています。
これらは NLog ターゲットに書き込まれます。サーバーが Redis や Azure Storage などの他のソケットからデータを送受信するたびに、ログにトレースが記録されます。
ただし、クライアントがサーバーに接続すると、WebSocket を開くときに http トレースが取得されますが、クライアントとサーバー間のデータのトレースは取得されません。
問題は基本的に、IIS が AspNetWebSocketContext.WebSocket に関するトレースに実際に何かを書き込むかどうかです。もしそうなら、どうすればこのデータを記録できますか?
私の構成を明確にするために、Nlog config:
<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" throwExceptions="false" autoReload="true">
<extensions>
<add assembly="NLog.Target.TimeRoll" />
</extensions>
<targets>
<target xsi:type="File" name="diag" fileName="${basedir}/${shortdate}.log" layout="${longdate} ${uppercase:${level}} ${message} ${exception:format=tostring}" />
<target xsi:type="TimeRoll" name="timedTarget" Limit="30" fileName="\Timed_" layout="${longdate} ${uppercase:${level}} ${message} ${exception:format=tostring}" />
</targets>
<rules>
<logger name="*" minlevel="Trace" writeTo="timedTarget,diag">
</rules>
</nlog>
そして web.config の関連部分
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.diagnostics>
<trace>
<listeners>
<add name="nlog" type="NLog.NLogTraceListener, NLog"></add>
</listeners>
</trace>
<sources>
<source name="System.Net" switchValue="All" tracemode="includehex" maxdatasize="250">
<listeners>
<add name="nlog" />
</listeners>
</source>
<source name="System.Net.Http" switchValue="All" tracemode="includehex" maxdatasize="250">
<listeners>
<add name="nlog" />
</listeners>
</source>
<source name="System.Net.Sockets" switchValue="All" tracemode="includehex" maxdatasize="250">
<listeners>
<add name="nlog" />
</listeners>
</source>
<source name="System.Net.WebSockets" switchValue="All" tracemode="includehex" maxdatasize="250">
<listeners>
<add name="nlog" />
</listeners>
</source>
</sources>
<switches>
</switches>
<sharedListeners>
<add name="nlog" type="NLog.NLogTraceListener, NLog" />
</sharedListeners>
</system.diagnostics>
</configuration>