* Add wireshark style logging in Kestrel * More Append! * Update third party notices Co-authored-by: Kahbazi <A.Kahbazi@gmail.com>
This commit is contained in:
parent
134850b4a2
commit
826bc84183
|
|
@ -267,4 +267,29 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
SOFTWARE.
|
||||
|
||||
License notice for BedrockFramework
|
||||
===================================
|
||||
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2019 David Fowler
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
|
|
|||
|
|
@ -145,32 +145,56 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal
|
|||
return;
|
||||
}
|
||||
|
||||
var builder = new StringBuilder($"{method}[{buffer.Length}] ");
|
||||
var builder = new StringBuilder();
|
||||
builder.Append(method);
|
||||
builder.Append("[");
|
||||
builder.Append(buffer.Length);
|
||||
builder.AppendLine("]");
|
||||
|
||||
var charBuilder = new StringBuilder();
|
||||
|
||||
// Write the hex
|
||||
for (int i = 0; i < buffer.Length; i++)
|
||||
{
|
||||
builder.Append(buffer[i].ToString("X2"));
|
||||
builder.Append(" ");
|
||||
}
|
||||
builder.AppendLine();
|
||||
builder.Append("{0}");
|
||||
|
||||
var rawDataBuilder = new StringBuilder();
|
||||
// Write the bytes as if they were ASCII
|
||||
for (int i = 0; i < buffer.Length; i++)
|
||||
{
|
||||
var bufferChar = (char)buffer[i];
|
||||
if (Char.IsControl(bufferChar))
|
||||
if (char.IsControl(bufferChar))
|
||||
{
|
||||
rawDataBuilder.Append("\\x");
|
||||
rawDataBuilder.Append(buffer[i].ToString("X2"));
|
||||
continue;
|
||||
charBuilder.Append(".");
|
||||
}
|
||||
rawDataBuilder.Append(bufferChar);
|
||||
else
|
||||
{
|
||||
charBuilder.Append(bufferChar);
|
||||
}
|
||||
|
||||
if ((i + 1) % 16 == 0)
|
||||
{
|
||||
builder.Append(" ");
|
||||
builder.Append(charBuilder.ToString());
|
||||
builder.AppendLine();
|
||||
charBuilder.Clear();
|
||||
}
|
||||
else if ((i + 1) % 8 == 0)
|
||||
{
|
||||
builder.Append(" ");
|
||||
charBuilder.Append(" ");
|
||||
}
|
||||
}
|
||||
if (charBuilder.Length > 0)
|
||||
{
|
||||
// 2 (between hex and char blocks) + num bytes left (3 per byte)
|
||||
builder.Append(string.Empty.PadRight(2 + (3 * (16 - charBuilder.Length))));
|
||||
// extra for space after 8th byte
|
||||
if (charBuilder.Length < 8)
|
||||
{
|
||||
builder.Append(" ");
|
||||
}
|
||||
builder.Append(charBuilder.ToString());
|
||||
}
|
||||
|
||||
_logger.LogDebug(builder.ToString(), rawDataBuilder.ToString());
|
||||
_logger.LogDebug(builder.ToString());
|
||||
}
|
||||
|
||||
// The below APM methods call the underlying Read/WriteAsync methods which will still be logged.
|
||||
|
|
|
|||
Loading…
Reference in New Issue