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) { 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(); } 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); var producerClient = getExceptionProducerClient(); if (producerClient == null) { return; } producerClient.sendLog(log); } public static LogBean getLogBean { get { if (logBean == null) { logBean = new LogBean(); } return logBean; } } } }