init
This commit is contained in:
commit
e124a47765
19374 changed files with 9806149 additions and 0 deletions
86
KretaWeb/Logger/LoginRequestBodyRenderer.cs
Normal file
86
KretaWeb/Logger/LoginRequestBodyRenderer.cs
Normal file
|
@ -0,0 +1,86 @@
|
|||
using System;
|
||||
using System.Text;
|
||||
using Kreta.Web.Logging.Logger;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace Kreta.Web.Logger
|
||||
{
|
||||
/// <summary>
|
||||
/// Logging field renderer
|
||||
/// </summary>
|
||||
class LoginRequestBodyRenderer : LoggingFieldRenderer
|
||||
{
|
||||
/// <summary>
|
||||
/// Secret log value
|
||||
/// </summary>
|
||||
const string SecretLogValue = "***";
|
||||
|
||||
/// <summary>
|
||||
/// Password
|
||||
/// </summary>
|
||||
const string Password = nameof(Password);
|
||||
|
||||
/// <summary>
|
||||
/// User
|
||||
/// </summary>
|
||||
const string UserName = nameof(UserName);
|
||||
|
||||
/// <summary>
|
||||
/// Render
|
||||
/// </summary>
|
||||
/// <param name="fieldName">Field</param>
|
||||
/// <param name="context">Context</param>
|
||||
public override void Render(string fieldName, LoggingFieldRendererContext context)
|
||||
{
|
||||
string contentBodyJsonText = context.GetFieldValue(fieldName) as string;
|
||||
|
||||
if (contentBodyJsonText != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
JObject contentBody = JsonConvert.DeserializeObject<JObject>(contentBodyJsonText);
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(contentBody.GetValue(Password, StringComparison.OrdinalIgnoreCase)?.ToString()))
|
||||
{
|
||||
contentBody[Password] = SecretLogValue;
|
||||
}
|
||||
|
||||
string userLoginName = contentBody.GetValue(UserName, StringComparison.OrdinalIgnoreCase)?.ToString();
|
||||
|
||||
StringBuilder requestUserIdentifier = new StringBuilder();
|
||||
if (userLoginName != null)
|
||||
{
|
||||
requestUserIdentifier.Append(userLoginName.ToUpper());
|
||||
|
||||
string requestUri = context.GetFieldValue(RequestResponseLoggingFields.Request.Uri) as string;
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(requestUri))
|
||||
{
|
||||
requestUserIdentifier.Append('/');
|
||||
|
||||
try
|
||||
{
|
||||
Uri uri = new Uri(requestUri);
|
||||
requestUserIdentifier.Append(uri.Authority.Split('.')[0]);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
requestUserIdentifier.Append($"[{ex.Message}]");
|
||||
}
|
||||
}
|
||||
|
||||
context.SetFieldValue(RequestResponseLoggingFields.Request.User, requestUserIdentifier.ToString());
|
||||
}
|
||||
|
||||
context.SetFieldValue(fieldName, contentBody.ToString());
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
context.SetFieldValue(fieldName, ex.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue