From 3f6685c77beeb12baf840733fb890860f4c26e7c Mon Sep 17 00:00:00 2001
From: mac <user@users-MacBook-Pro.local>
Date: 星期四, 25 七月 2024 17:25:59 +0800
Subject: [PATCH] 2024年07月25日17:24:45

---
 HDL-ON_Android/Aliyu/AliyuLogUtil.cs |   31 +++++++++++++++++++------------
 1 files changed, 19 insertions(+), 12 deletions(-)

diff --git a/HDL-ON_Android/Aliyu/AliyuLogUtil.cs b/HDL-ON_Android/Aliyu/AliyuLogUtil.cs
index 33614d0..912963b 100644
--- a/HDL-ON_Android/Aliyu/AliyuLogUtil.cs
+++ b/HDL-ON_Android/Aliyu/AliyuLogUtil.cs
@@ -7,7 +7,6 @@
     public class AliyuLogUtil
     {
         private static AliyuLogProducerClient exceptionProducerClient;
-
         private static LogBean logBean;
 
         private static AliyuLogProducerClient getExceptionProducerClient()
@@ -16,6 +15,9 @@
             {
                 if (exceptionProducerClient == null)
                 {
+                    if (Shared.Application.Activity == null) {
+                        return null;
+                    }
                     exceptionProducerClient = new AliyuLogProducerClient(Shared.Application.Activity, "https://cn-hangzhou.log.aliyuncs.com", "log", "event_tracking", "LTAI5tLzDxrtsFyi3xtK3YWt", "eX31JZrRAvC2wZWPiZU0SYhlfAUMoT", null, null);
                     exceptionProducerClient.initProducer();
                 }
@@ -65,7 +67,7 @@
              * 1.鐐瑰嚮椤圭洰鐨勬椂鍊欒缃�
              * 2.鍏抽棴浣忓畢椤甸潰鐨勬椂鍊欏幓鎺�
              */
-            if (string.IsNullOrEmpty(getLogBean().getUserId()) || string.IsNullOrEmpty(getLogBean().getHomeId()))
+            if (string.IsNullOrEmpty(getLogBean.getUserId()) || string.IsNullOrEmpty(getLogBean.getHomeId()))
             {
                 return;
             }
@@ -73,22 +75,27 @@
             log.PutContent("title", title);
             log.PutContent("content", content);
             log.PutContent("level", level.ToString());
-            log.PutContent("userId", getLogBean().getUserId());
-            log.PutContent("homeId", getLogBean().getHomeId());
+            log.PutContent("userId", getLogBean.getUserId());
+            log.PutContent("homeId", getLogBean.getHomeId());
             log.PutContent("time", System.DateTime.UtcNow + "");
-            log.PutContent("userAgent", getLogBean().getUserAgent());
-            log.PutContent("appVersion", getLogBean().getAppVersion());
+            log.PutContent("userAgent", getLogBean.getUserAgent());
+            log.PutContent("appVersion", getLogBean.getAppVersion());
             log.PutContent("type", type);
             log.PutContent("exceptionBlock", exceptionBlock);
-            getExceptionProducerClient().sendLog(log);
+
+            var producerClient = getExceptionProducerClient();
+            if (producerClient == null)
+            {
+                return;
+            }
+            producerClient.sendLog(log);
+
         }
 
-        public static LogBean getLogBean()
+        public static LogBean getLogBean
         {
-            lock (logBean)
-            {
-                if (null == logBean)
-                {
+            get {
+                if (logBean == null) {
                     logBean = new LogBean();
                 }
                 return logBean;

--
Gitblit v1.8.0