2

I'm using IIS 10 and need to trace the traffic flowing in and out from the .NET 4.5.2 WebSocket that is created when someone opens a websocket to the server, this seems to be quite impossible.

The current trace configuration is logging System.Net, System.Net.Http, System.Net.Sockets and System.Net.WebSockets.

These are written to a NLog target. Whenever the server sends or receives data from other sockets, like Redis or Azure Storage, i get traces in my log.

However when a client connects to the server, i get http trace when opening the WebSocket, but no trace of data between the client and server.

The question is basically, does IIS actually write anything to tracing regarding the AspNetWebSocketContext.WebSocket ? If so, how can i log this data?

To clarify my configuration, 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>

And the relevant part of the 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>
Crypth
  • 1,576
  • 18
  • 32
  • Your description lacks of basic information. How do you use NLog? There is System.Net tracing to get all network packets but does NLog itself have the same capability? – Lex Li Feb 12 '16 at 15:08
  • I'm using multiple NLog targets, but it's actually irrelevant. NLog only writes any systems.diagnostics trace data to a target log of choice. In my case i'm writing to a file and to a rolling in memory log created for this specific purpose. I added the information to indicate that i know that the logging itself isn't an issue. I am getting networks packets from System.Net but not the ones from the open Websocket. I'll add my configurations to the question. – Crypth Feb 12 '16 at 15:15

0 Answers0