hxb
2023-06-14 8d68145cc5e007bfc662ef8bb436b716519f956e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
using System;
using Android.Content;
using Com.Aliyun.Sls.Android.Producer;
 
namespace HDL_ON_Android.Aliyu
{
    public class AliyuLogUtil
    {
        private static AliyuLogProducerClient exceptionProducerClient;
 
        private static LogBean logBean;
 
        private static AliyuLogProducerClient getExceptionProducerClient()
        {
            lock (exceptionProducerClient)
            {
                if (exceptionProducerClient == null)
                {
                    exceptionProducerClient = new AliyuLogProducerClient(Shared.Application.Activity, "https://cn-hangzhou.log.aliyuncs.com", "log", "event_tracking", "LTAI5tLzDxrtsFyi3xtK3YWt", "eX31JZrRAvC2wZWPiZU0SYhlfAUMoT", null, null);
                    exceptionProducerClient.initProducer();
                }
                return exceptionProducerClient;
            }
        }
 
 
        /**
         * 异常日志
         *
         * @param title    标题
         * @param content  附加数据内容
         * @param level    报警等级
         */
        public static void log(string title, string content, Level level)
        {
            log(title, content, level, null);
        }
        /**
         * 异常日志
         *
         * @param title    标题
         * @param content  附加数据内容
         * @param otherMsg 其他附加数据,没有可为空
         * @param level    报警等级
         * @param type 异常类型
         */
        public static void log(string title, string content, Level level, string type)
        {
            log(title, content, level, null, null);
        }
        /**
         * 异常日志
         *
         * @param title    标题
         * @param content  附加数据内容
         * @param otherMsg 其他附加数据,没有可为空
         * @param level    报警等级
         * @param type 异常类型
         * @param exceptionBlock 异常代码块
         */
        public static void log(string title, string content, Level level, string type, string exceptionBlock)
        {
            /**
             * 没有homeId和userId  不允许上传   只上传住宅里面的异常  减少云端压力
             * 1.点击项目的时候设置
             * 2.关闭住宅页面的时候去掉
             */
            if (string.IsNullOrEmpty(getLogBean().getUserId()) || string.IsNullOrEmpty(getLogBean().getHomeId()))
            {
                return;
            }
            Log log = new Log();
            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("time", System.DateTime.UtcNow + "");
            log.PutContent("userAgent", getLogBean().getUserAgent());
            log.PutContent("appVersion", getLogBean().getAppVersion());
            log.PutContent("type", type);
            log.PutContent("exceptionBlock", exceptionBlock);
            getExceptionProducerClient().sendLog(log);
        }
 
        public static LogBean getLogBean()
        {
            lock (logBean)
            {
                if (null == logBean)
                {
                    logBean = new LogBean();
                }
                return logBean;
            }
        }
    }
}