Robert 1 жил өмнө
parent
commit
7da16f3497

+ 2 - 0
EVCB_OCPP.WSServer/HostedProtalServer.cs

@@ -1,4 +1,5 @@
 using EVCB_OCPP.Domain.Extensions;
+using EVCB_OCPP.Service;
 using EVCB_OCPP.WSServer.Helper;
 using EVCB_OCPP.WSServer.Jobs;
 using EVCB_OCPP.WSServer.Message;
@@ -20,6 +21,7 @@ namespace EVCB_OCPP.WSServer
             services.AddPortalServerDatabase(configuration);
             services.AddBusinessServiceFactory();
 
+            services.AddHeaderRecordService();
             services.AddOcppWsServer();
 
             services.AddSingleton<ServerMessageService>();

+ 4 - 2
EVCB_OCPP.WSServer/Program.cs

@@ -6,6 +6,8 @@ using EVCB_OCPP.WSServer.Helper;
 using Microsoft.AspNetCore.Builder;
 using Microsoft.AspNetCore.Hosting;
 using EVCB_OCPP.WSServer.Service.WsService;
+using EVCB_OCPP.Service;
+using Microsoft.Extensions.Logging;
 
 namespace EVCB_OCPP.WSServer
 {
@@ -44,14 +46,14 @@ namespace EVCB_OCPP.WSServer
                 {
                     //services.AddSingleton<MeterValueGroupSingleHandler>();
                     //services.AddSingleton<IHostLifetime, DummyHostLifeTime>();
-
                     services.AddProtalServer(hostContext.Configuration);
 
                     //services.AddTransient<BlockingTreePrintService>();
                     //services.AddTransient<GoogleGetTimePrintService>();
                 });
             var app = builder.Build();
-            app.MapOcppWsService();
+            app.UseHeaderRecordService();
+            app.UseOcppWsService();
             app.MapApiServce();
             app.Urls.Add("http://*:80");
             app.Run();

+ 0 - 181
EVCB_OCPP.WSServer/ProtalServer.cs

@@ -337,195 +337,14 @@ namespace EVCB_OCPP.WSServer
 
         private void StartWsService()
         {
-            websocketService.ValidateHandshake = WebsocketServiceValidateHandshake;
             websocketService.NewSessionConnected += AppServer_NewSessionConnected;
         }
 
         private void StopWsService()
         {
-            websocketService.ValidateHandshake = null;
             websocketService.NewSessionConnected -= AppServer_NewSessionConnected;
         }
 
-        private async Task<bool> WebsocketServiceValidateHandshake(WsClientData session)
-        {
-            session.ISOCPP20 = session.SecWebSocketProtocol.ToLower().Contains("ocpp2.0");
-
-            int securityProfile = 0;
-            string authorizationKey = string.Empty;
-            if (string.IsNullOrEmpty(session.Path))
-            {
-                //logger.Log();
-                logger.LogWarning("===========================================");
-                logger.LogWarning("session.Path EMPTY");
-                logger.LogWarning("===========================================");
-            }
-
-            string[] words = session.Path.ToString().Split('/');
-            session.ChargeBoxId = words.Last();
-            logger.LogDebug("{0}:{1}", session.ChargeBoxId, session.UriScheme);
-
-            foreach (var denyModel in GlobalConfig.DenyModelNames)
-            {
-                if (string.IsNullOrEmpty(denyModel))
-                {
-                    continue;
-                }
-
-                if (session.ChargeBoxId.StartsWith(denyModel))
-                {
-
-                    StringBuilder responseBuilder = new StringBuilder();
-
-                    responseBuilder.AppendFormatWithCrCf(@"HTTP/{0} {1} {2}", "1.1",
-                    (int)HttpStatusCode.Unauthorized, @"Unauthorized");
-
-                    responseBuilder.AppendWithCrCf();
-                    string sb = responseBuilder.ToString();
-                    //byte[] data = Encoding.UTF8.GetBytes(sb);
-
-                    await session.Send(sb);
-                    logger.LogTrace(sb);
-                    return false;
-                }
-            }
-
-            if (configuration["MaintainMode"] == "1")
-            {
-                session.ChargeBoxId = session.ChargeBoxId + "_2";
-            }
-
-            logger.LogInformation(string.Format("ValidateHandshake: {0}", session.Path));
-            bool isExistedSN = false;
-            bool authorizated = false;
-
-            var info = mainDbService.GetMachineIdAndCustomerInfo(session.ChargeBoxId).Result;
-            //var machine = db.Machine.Where(x => x.ChargeBoxId == session.ChargeBoxId && x.IsDelete == false).Select(x => new { x.CustomerId, x.Id }).AsNoTracking().FirstOrDefault();
-            //session.CustomerName = machine == null ? "Unknown" : db.Customer.Where(x => x.Id == machine.CustomerId).Select(x => x.Name).FirstOrDefault();
-            //session.CustomerId = machine == null ? Guid.Empty : machine.CustomerId;
-            //session.MachineId = machine == null ? String.Empty : machine.Id;
-            //isExistedSN = machine == null ? false : true;
-            session.CustomerName = info.CustomerName;
-            session.CustomerId = info.CustomerId;
-            session.MachineId = info.MachineId;
-            isExistedSN = !string.IsNullOrEmpty(info.MachineId);// machine == null ? false : true;
-
-            if (!isExistedSN)
-            {
-                StringBuilder responseBuilder = new StringBuilder();
-
-                responseBuilder.AppendFormatWithCrCf(@"HTTP/{0} {1} {2}", "1.1",
-                (int)HttpStatusCode.NotFound, @"Not Found");
-
-                responseBuilder.AppendWithCrCf();
-                string sb = responseBuilder.ToString();
-                //byte[] data = Encoding.UTF8.GetBytes(sb);
-                await session.Send(sb);
-
-                logger.LogInformation(sb);
-                return false;
-            }
-
-            //var configVaule = db.MachineConfigurations.Where(x => x.ChargeBoxId == session.ChargeBoxId && x.ConfigureName == StandardConfiguration.SecurityProfile)
-            //                  .Select(x => x.ConfigureSetting).FirstOrDefault();
-            var configVaule = mainDbService.GetMachineSecurityProfile(session.ChargeBoxId).Result;
-            int.TryParse(configVaule, out securityProfile);
-
-            if (session.ISOCPP20)
-            {
-                // 1.6 server only support change server  function
-                securityProfile = 0;
-            }
-
-            if (securityProfile == 3 && session.UriScheme == "ws")
-            {
-                StringBuilder responseBuilder = new StringBuilder();
-
-                responseBuilder.AppendFormatWithCrCf(@"HTTP/{0} {1} {2}", "1.1",
-                (int)HttpStatusCode.Unauthorized, @"Unauthorized");
-
-                responseBuilder.AppendWithCrCf();
-                string sb = responseBuilder.ToString();
-                //byte[] data = Encoding.UTF8.GetBytes(sb);
-
-                await session.Send(sb);
-                logger.LogInformation(sb);
-                return false;
-            }
-
-            if (securityProfile == 1 || securityProfile == 2)
-            {
-                if (securityProfile == 2 && session.UriScheme == "ws")
-                {
-                    authorizated = false;
-                }
-
-                //if (session.Items.ContainsKey("Authorization") || session.Items.ContainsKey("authorization"))
-                if (!string.IsNullOrEmpty(session.AuthHeader))
-                {
-                    //authorizationKey = db.MachineConfigurations.Where(x => x.ChargeBoxId == session.ChargeBoxId && x.ConfigureName == StandardConfiguration.AuthorizationKey)
-                    //                    .Select(x => x.ConfigureSetting).FirstOrDefault();
-                    authorizationKey = await mainDbService.GetMachineAuthorizationKey(session.ChargeBoxId);
-
-                    if (session.ISOCPP20)
-                    {
-                        // 1.6 server only support change server  function
-                        securityProfile = 0;
-                    }
-
-                    logger.LogInformation("***********Authorization   ");
-
-                    if (!string.IsNullOrEmpty(authorizationKey))
-                    {
-                        //string base64Encoded = session.Items.ContainsKey("Authorization") ? session.Items["Authorization"].ToString().Replace("Basic ", "") : session.Items["authorization"].ToString().Replace("Basic ", "");
-                        string base64Encoded = session.AuthHeader.Replace("Basic ", "");
-                        byte[] data = Convert.FromBase64String(base64Encoded);
-                        string[] base64Decoded = Encoding.ASCII.GetString(data).Split(':');
-                        logger.LogInformation("***********Authorization   " + Encoding.ASCII.GetString(data));
-                        if (base64Decoded.Count() == 2 && base64Decoded[0] == session.ChargeBoxId && base64Decoded[1] == authorizationKey)
-                        {
-                            authorizated = true;
-                        }
-                    }
-
-
-
-
-
-                }
-                else
-                {
-                    authorizated = true;
-
-                }
-
-
-
-                if (!authorizated)
-                {
-                    StringBuilder responseBuilder = new StringBuilder();
-
-                    responseBuilder.AppendFormatWithCrCf(@"HTTP/{0} {1} {2}", "1.1",
-                    (int)HttpStatusCode.Unauthorized, @"Unauthorized");
-
-                    responseBuilder.AppendWithCrCf();
-                    string sb = responseBuilder.ToString();
-                    //byte[] data = Encoding.UTF8.GetBytes(sb);
-
-                    await session.Send(sb);
-                    logger.LogInformation(sb);
-                    return false;
-                }
-            }
-
-
-
-
-
-            logger.LogInformation(string.Format("ValidateHandshake PASS: {0}", session.Path));
-            return true;
-        }
-
         private async void AppServer_NewSessionConnected(object sender, WsClientData session)
         {
             logger.LogDebug(string.Format("{0} NewSessionConnected", session.Path));

+ 65 - 0
EVCB_OCPP.WSServer/Service/HeaderRecordService.cs

@@ -0,0 +1,65 @@
+using Azure.Core;
+using HeaderRecord;
+using Microsoft.AspNetCore.Builder;
+using Microsoft.AspNetCore.Http;
+using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Extensions.Logging;
+using System.Net.Http;
+
+namespace EVCB_OCPP.Service
+{
+    public static partial class AppExtention
+    {
+        public static void AddHeaderRecordService(this IServiceCollection services)
+        {
+            services.AddTransient<HeaderRecordService>();
+        }
+
+        public static void UseHeaderRecordService(this WebApplication webApplication)
+        {
+            webApplication.Use(async (context, next) =>
+            {
+                var servcie = context.RequestServices.GetService<HeaderRecordService>();
+                servcie.LogRequest(context.TraceIdentifier, context.Request);
+                await next(context);
+                servcie.LogResponse(context.TraceIdentifier, context.Response);
+                return;
+            });
+        }
+    }
+}
+
+namespace HeaderRecord
+{
+
+    public class HeaderRecordService
+    {
+        private readonly ILogger<HeaderRecordService> logger;
+
+        public HeaderRecordService(ILogger<HeaderRecordService> logger)
+        {
+            this.logger = logger;
+        }
+
+        internal void LogRequest(string traceIdentifier, HttpRequest request)
+        {
+            logger.LogInformation("LogRequest============================================================");
+            logger.LogInformation("{id} {method} {path} {protocol}", traceIdentifier, request.Method, request.Path, request.Protocol);
+            foreach (var headerKey in request.Headers.Keys)
+            {
+                logger.LogInformation("{id} {key} {value}", traceIdentifier, headerKey, request.Headers[headerKey]);
+            }
+            logger.LogInformation("LogRequest============================================================");
+        }
+
+        internal void LogResponse(string traceIdentifier, HttpResponse response)
+        {
+            logger.LogInformation("LogResponse============================================================");
+            foreach (var headerKey in response.Headers.Keys)
+            {
+                logger.LogInformation("{id} {key} {value}", traceIdentifier, headerKey, response.Headers[headerKey]);
+            }
+            logger.LogInformation("LogResponse============================================================");
+        }
+    }
+}

+ 148 - 6
EVCB_OCPP.WSServer/Service/WsService/OcppWebsocketService.cs

@@ -1,13 +1,14 @@
 using Microsoft.AspNetCore.Builder;
 using Microsoft.AspNetCore.Http;
+using Microsoft.Extensions.Configuration;
 using Microsoft.Extensions.DependencyInjection;
 using Microsoft.Extensions.Logging;
-using Newtonsoft.Json;
 using System.Net.WebSockets;
+using System.Text;
 
 namespace EVCB_OCPP.WSServer.Service.WsService;
 
-public static class AppExtention
+public static partial class AppExtention
 {
     public static void AddOcppWsServer(this IServiceCollection services)
     {
@@ -15,7 +16,7 @@ public static class AppExtention
         services.AddSingleton<OcppWebsocketService>();
     }
 
-    public static void MapOcppWsService(this WebApplication webApplication)
+    public static void UseOcppWsService(this WebApplication webApplication)
     {
         webApplication.UseWebSockets(new WebSocketOptions()
         {
@@ -40,24 +41,31 @@ public static class AppExtention
 public class OcppWebsocketService : WebsocketService<WsClientData>
 {
     public static List<string> protocals = new List<string>() { "", "ocpp1.6", "ocpp2.0.1" };
+
+    private readonly IConfiguration configuration;
+    private readonly IMainDbService mainDbService;
     private readonly ILogger<OcppWebsocketService> logger;
 
     public OcppWebsocketService(
+        IConfiguration configuration,
         IServiceProvider serviceProvider,
+        IMainDbService mainDbService,
         ILogger<OcppWebsocketService> logger
         ) : base(serviceProvider)
     {
+        this.configuration = configuration;
+        this.mainDbService = mainDbService;
         this.logger = logger;
     }
 
-    internal override async ValueTask<string> AcceptWebSocketHandler(HttpContext context)
+    internal override async ValueTask<string> ValidateSupportedPortocol(HttpContext context)
     {
-        logger.LogInformation("{function}:{Path}/{SubProtocol}", nameof(AcceptWebSocketHandler), context.Request.Path, context.WebSockets.WebSocketRequestedProtocols);
+        logger.LogInformation("{id} {function}:{Path}/{SubProtocol}", context.TraceIdentifier, nameof(ValidateSupportedPortocol), context.Request.Path, context.WebSockets.WebSocketRequestedProtocols);
 
         var protocol = GetSupportedPortocol(context.WebSockets.WebSocketRequestedProtocols, protocals);
         if (string.IsNullOrEmpty(protocol))
         {
-            logger.LogInformation("{function}:{Path} Protocol Not Supported, Disconnecting", nameof(AcceptWebSocketHandler), context.Request.Path);
+            logger.LogInformation("{id} {function}:{Path} Protocol Not Supported, Disconnecting", context.TraceIdentifier, nameof(ValidateSupportedPortocol), context.Request.Path);
 
             using WebSocket toRejectwebSocket = await context.WebSockets.AcceptWebSocketAsync();
             await toRejectwebSocket.CloseAsync(WebSocketCloseStatus.NormalClosure, null, default);
@@ -66,6 +74,140 @@ public class OcppWebsocketService : WebsocketService<WsClientData>
         return protocol;
     }
 
+    internal override async ValueTask<bool> ValidateHandshake(HttpContext context, WsClientData session)
+    {
+        string authHeader = context?.Request?.Headers?.Authorization;
+
+        session.ISOCPP20 = context.WebSockets.WebSocketRequestedProtocols.Any(x => x.ToLower() == "ocpp2.0");
+
+        int securityProfile = 0;
+        string authorizationKey = string.Empty;
+        if (string.IsNullOrEmpty(session.Path))
+        {
+            //logger.Log();
+            logger.LogWarning("===========================================");
+            logger.LogWarning("{id} session.Path EMPTY", context.TraceIdentifier);
+            logger.LogWarning("===========================================");
+        }
+
+        string[] words = session.Path.ToString().Split('/');
+        session.ChargeBoxId = words.Last();
+        logger.LogDebug("{id} {0}:{1}", context.TraceIdentifier, session.ChargeBoxId, session.UriScheme);
+
+        foreach (var denyModel in GlobalConfig.DenyModelNames)
+        {
+            if (string.IsNullOrEmpty(denyModel))
+            {
+                continue;
+            }
+
+            if (session.ChargeBoxId.StartsWith(denyModel))
+            {
+                context.Response.StatusCode = StatusCodes.Status401Unauthorized;
+
+                logger.LogTrace("{id} {func} {Statuscode}", context.TraceIdentifier, nameof(ValidateHandshake), context.Response.StatusCode);
+                return false;
+            }
+        }
+
+        if (configuration["MaintainMode"] == "1")
+        {
+            session.ChargeBoxId = session.ChargeBoxId + "_2";
+        }
+
+        logger.LogInformation("{id} ValidateHandshake: {0}", context.TraceIdentifier, session.Path);
+        bool isExistedSN = false;
+        bool authorizated = false;
+
+        var info = await mainDbService.GetMachineIdAndCustomerInfo(session.ChargeBoxId);
+        //var machine = db.Machine.Where(x => x.ChargeBoxId == session.ChargeBoxId && x.IsDelete == false).Select(x => new { x.CustomerId, x.Id }).AsNoTracking().FirstOrDefault();
+        //session.CustomerName = machine == null ? "Unknown" : db.Customer.Where(x => x.Id == machine.CustomerId).Select(x => x.Name).FirstOrDefault();
+        //session.CustomerId = machine == null ? Guid.Empty : machine.CustomerId;
+        //session.MachineId = machine == null ? String.Empty : machine.Id;
+        //isExistedSN = machine == null ? false : true;
+        session.CustomerName = info.CustomerName;
+        session.CustomerId = info.CustomerId;
+        session.MachineId = info.MachineId;
+        isExistedSN = !string.IsNullOrEmpty(info.MachineId);// machine == null ? false : true;
+
+        if (!isExistedSN)
+        {
+            context.Response.StatusCode = StatusCodes.Status404NotFound;
+            logger.LogTrace("{id} {func} {Statuscode}", context.TraceIdentifier, nameof(ValidateHandshake), context.Response.StatusCode);
+            return false;
+        }
+
+        //var configVaule = db.MachineConfigurations.Where(x => x.ChargeBoxId == session.ChargeBoxId && x.ConfigureName == StandardConfiguration.SecurityProfile)
+        //                  .Select(x => x.ConfigureSetting).FirstOrDefault();
+        var configVaule = mainDbService.GetMachineSecurityProfile(session.ChargeBoxId).Result;
+        int.TryParse(configVaule, out securityProfile);
+
+        if (session.ISOCPP20)
+        {
+            // 1.6 server only support change server  function
+            securityProfile = 0;
+        }
+
+        if (securityProfile == 3 && session.UriScheme == "ws")
+        {
+            context.Response.StatusCode = StatusCodes.Status401Unauthorized;
+            logger.LogTrace("{id} {func} {Statuscode}", context.TraceIdentifier, nameof(ValidateHandshake), context.Response.StatusCode);
+            return false;
+        }
+
+        if (securityProfile == 1 || securityProfile == 2)
+        {
+            if (securityProfile == 2 && session.UriScheme == "ws")
+            {
+                authorizated = false;
+            }
+
+            //if (session.Items.ContainsKey("Authorization") || session.Items.ContainsKey("authorization"))
+            if (!string.IsNullOrEmpty(authHeader))
+            {
+                //authorizationKey = db.MachineConfigurations.Where(x => x.ChargeBoxId == session.ChargeBoxId && x.ConfigureName == StandardConfiguration.AuthorizationKey)
+                //                    .Select(x => x.ConfigureSetting).FirstOrDefault();
+                authorizationKey = await mainDbService.GetMachineAuthorizationKey(session.ChargeBoxId);
+
+                if (session.ISOCPP20)
+                {
+                    // 1.6 server only support change server  function
+                    securityProfile = 0;
+                }
+
+                logger.LogInformation("{id} ***********Authorization   ", context.TraceIdentifier);
+
+                if (!string.IsNullOrEmpty(authorizationKey))
+                {
+                    //string base64Encoded = session.Items.ContainsKey("Authorization") ? session.Items["Authorization"].ToString().Replace("Basic ", "") : session.Items["authorization"].ToString().Replace("Basic ", "");
+                    string base64Encoded = authHeader.Replace("Basic ", "");
+                    byte[] data = Convert.FromBase64String(base64Encoded);
+                    string[] base64Decoded = Encoding.ASCII.GetString(data).Split(':');
+                    logger.LogInformation("{id} ***********Authorization   " + Encoding.ASCII.GetString(data), context.TraceIdentifier);
+                    if (base64Decoded.Count() == 2 && base64Decoded[0] == session.ChargeBoxId && base64Decoded[1] == authorizationKey)
+                    {
+                        authorizated = true;
+                    }
+                }
+            }
+            else
+            {
+                authorizated = true;
+
+            }
+
+            if (!authorizated)
+            {
+                context.Response.StatusCode = StatusCodes.Status401Unauthorized;
+                logger.LogTrace("{id} {func} {Statuscode}", context.TraceIdentifier, nameof(ValidateHandshake), context.Response.StatusCode);
+                return false;
+            }
+        }
+
+        logger.LogInformation("{id} ValidateHandshake PASS: {0}", context.TraceIdentifier, session.Path);
+        return true;
+    }
+
     private static string GetSupportedPortocol(IList<string> clientProtocols, IList<string> supportedProtocols)
     {
         int supportedProtocolIndex = supportedProtocols.Count - 1;

+ 27 - 21
EVCB_OCPP.WSServer/Service/WsService/WebsocketService.cs

@@ -1,6 +1,7 @@
 using Microsoft.AspNetCore.Http;
 using Microsoft.Extensions.DependencyInjection;
 using System.Net;
+using System.Net.Http;
 using System.Net.WebSockets;
 
 namespace EVCB_OCPP.WSServer.Service.WsService;
@@ -12,7 +13,6 @@ public class WebsocketService<T> where T : WsSession
         this.serviceProvider = serviceProvider;
     }
 
-    public Func<T, Task<bool>> ValidateHandshake;
     private readonly IServiceProvider serviceProvider;
 
     public event EventHandler<T> NewSessionConnected;
@@ -24,35 +24,50 @@ public class WebsocketService<T> where T : WsSession
             return;
         }
 
-        var portocol = await AcceptWebSocketHandler(context);
+        var portocol = await ValidateSupportedPortocol(context);
         if (string.IsNullOrEmpty(portocol))
         {
             return;
         }
 
+        T data = GetSession(context);
+
+        if (!await ValidateHandshake(context, data))
+        {
+            return;
+        }
+
         using WebSocket webSocket = await context.WebSockets.AcceptWebSocketAsync(portocol);
-        await AddWebSocket(webSocket, context);
+        await AddWebSocket(webSocket, data);
+    }
+
+    internal virtual ValueTask<bool> ValidateHandshake(HttpContext context, T data)
+    {
+        return ValueTask.FromResult(true);
     }
 
-    internal virtual ValueTask<string> AcceptWebSocketHandler(HttpContext context)
+    internal virtual ValueTask<string> ValidateSupportedPortocol(HttpContext context)
     {
         return ValueTask.FromResult(string.Empty);
     }
 
 
-    public async Task AddWebSocket(WebSocket webSocket, HttpContext context)
+    private async Task AddWebSocket(WebSocket webSocket, T data)
+    {
+        data.ClientWebSocket = webSocket;
+
+        NewSessionConnected?.Invoke(this, data);
+        await data.EndConnSemaphore.WaitAsync();
+        return;
+    }
+
+    private T GetSession(HttpContext context)
     {
         T data = serviceProvider.GetRequiredService<T>();
         data.Path = context?.Request?.Path;
-        data.ClientWebSocket = webSocket;
         data.SessionID = context.TraceIdentifier;
-        //data.UriScheme = context?.Request?.Scheme;
-        data.AuthHeader = context?.Request?.Headers?.Authorization;
-        //data.Origin = context.Request.Scheme;
-
         data.UriScheme = GetScheme(context);
 
-
         try
         {
             var ipaddress = context.Connection.RemoteIpAddress;
@@ -64,16 +79,7 @@ public class WebsocketService<T> where T : WsSession
             data.Endpoint = null;
         }
 
-        var validated = ValidateHandshake == null ? false : await ValidateHandshake(data);
-
-        if (!validated)
-        {
-            return;
-        }
-
-        NewSessionConnected?.Invoke(this, data);
-        await data.EndConnSemaphore.WaitAsync();
-        return;
+        return data;
     }
 
     private string GetScheme(HttpContext context)

+ 4 - 6
EVCB_OCPP.WSServer/Service/WsService/WsSession.cs

@@ -15,10 +15,8 @@ public class WsSession
 
     public PathString? Path { get; set; }
     public string UriScheme { get; set; }
-    public string AuthHeader { get; set; }
     public string SessionID { get; set; }
     public IPEndPoint Endpoint { get; internal set; }
-    //public StringValues Origin { get; internal set; }
     public DateTime LastActiveTime { get; set; }
 
 
@@ -53,7 +51,7 @@ public class WsSession
 
     private async Task StartReceivd(WebSocket webSocket, CancellationToken token)
     {
-        logger.LogInformation("{func}:{Path} Start", nameof(StartReceivd), Path);
+        logger.LogInformation("{id} {func} {Path} Start", SessionID, nameof(StartReceivd), Path);
 
         byte[] receivdBuffer = new byte[0];
         int bufferExpand = 1;
@@ -92,7 +90,7 @@ public class WsSession
             }
 
             var received = Encoding.UTF8.GetString(receivdBuffer, 0, receivedBytes);
-            logger.LogInformation("{func}:{Path} {value}", nameof(StartReceivd), Path, received);
+            //logger.LogInformation("{func}:{Path} {value}", nameof(StartReceivd), Path, received);
 
             HandleReceivedData(received);
 
@@ -108,7 +106,7 @@ public class WsSession
 
     internal Task Send(string dataString)
     {
-        logger.LogInformation("{func}:{Path} {value}", nameof(Send), Path, dataString);
+        //logger.LogInformation("{func}:{Path} {value}", nameof(Send), Path, dataString);
 
         var data = Encoding.UTF8.GetBytes(dataString);
         return Send(data);
@@ -127,7 +125,7 @@ public class WsSession
         }
         catch (Exception e)
         {
-            logger.LogInformation("{func}:{Path} exception:{msg}", nameof(Send), Path, e.Message);
+            logger.LogInformation("{func} {Path} exception:{msg}", nameof(Send), Path, e.Message);
         }
     }
 

+ 8 - 2
EVCB_OCPP.WSServer/appsettings.json

@@ -40,8 +40,14 @@
     },
     "rules": [
       {
-        "ruleName": "EVCB_OCPP.WSServer.Service.WsService",
-        "logger": "EVCB_OCPP.WSServer.Service.WsService.*",
+        "ruleName": "HttpRecord",
+        "logger": "HeaderRecord*",
+        "minLevel": "Info",
+        "writeTo": "ws"
+      },
+      {
+        "ruleName": "WsRecord",
+        "logger": "EVCB_OCPP.WSServer.Service.WsService*",
         "minLevel": "Info",
         "writeTo": "ws"
       },