zinab_elgendy преди 2 седмици
родител
ревизия
3ea93e6370
променени са 1 файла, в които са добавени 9 реда и са изтрити 6 реда
  1. 9 6
      MTWorkHR.Application/Chat/ChatHub.cs

+ 9 - 6
MTWorkHR.Application/Chat/ChatHub.cs

@@ -1,6 +1,7 @@
 using Microsoft.AspNetCore.Identity;
 using Microsoft.AspNetCore.SignalR;
 using Microsoft.EntityFrameworkCore;
+using Microsoft.Extensions.Logging;
 using MimeKit;
 using MTWorkHR.Application.Filters;
 using MTWorkHR.Application.Identity;
@@ -27,13 +28,14 @@ namespace MTWorkHR.API.Chat
         private readonly GlobalInfo _globalInfo;
         //private readonly UserService _userService; 
         private readonly ApplicationUserManager _userManager;
-
-        public ChatHub(IUnitOfWork unitOfWork, GlobalInfo globalInfo, ApplicationUserManager userManager /*, UserService userService*/) 
+        private readonly ILogger<ChatHub> _logger;
+        public ChatHub(IUnitOfWork unitOfWork, GlobalInfo globalInfo, ApplicationUserManager userManager /*, UserService userService*/, ILogger<ChatHub> logger) 
         {
             _unitOfWork = unitOfWork;
             _globalInfo = globalInfo;
             //  _userService = userService;
             _userManager = userManager;
+            _logger = logger;
         }
 
         public async Task GetUsers()
@@ -73,7 +75,8 @@ namespace MTWorkHR.API.Chat
             }catch(Exception e)
             {
                 var m = e.Message;
-                Console.WriteLine(e.Message);
+
+                _logger.LogError(e, e.Message);
             }
 
             return response;
@@ -97,7 +100,7 @@ namespace MTWorkHR.API.Chat
       
         // Send a message from one user to another
        
-        public async Task sendMsg(string receiverUserId, string msg)
+        public async Task SendMessage(string receiverUserId, string msg)
         {
             try
             {
@@ -120,7 +123,7 @@ namespace MTWorkHR.API.Chat
                 await Clients.Client(receiverconnIdDB).SendAsync("ReceiveMessage", messag);
                 await Clients.Caller.SendAsync("ReceiveMessage", messag);
             }
-            catch (Exception e) { }
+            catch (Exception e) { _logger.LogError(e, e.Message); }
         }
 
         // Get previous messages between two users
@@ -196,7 +199,7 @@ namespace MTWorkHR.API.Chat
                     await Clients.Caller.SendAsync("authMeResponseFail");
                 }
             }
-            catch (Exception ex) { }
+            catch (Exception e) { _logger.LogError(e, e.Message); }
 
             await base.OnConnectedAsync();
         }