云日志服务.NET SDK 3.1. 基本使用 使用 SDK访问云日志服务,需要设置正确的 AccessKey、SecretKey 和endpoint,所有的服务可以使用同一 key 凭证来进行访问,但不同的服务地区需要使用不同的 endpoint 进行访问,详情参考天翼云官网SDK接入概述。在调用前SDK,需要已知以下参数: 云日志服务访问地址。详情请查看访问地址(Endpoint)。 key凭证:accessKey和secretKey 。详情请查看如何获取访问密钥(AK/SK)。 日志项目编码:logProject,在使用SDK前,需要确保您有至少一个已经存在的日志项目。 日志单元编码:logUnit,在使用SDK前,需要确保日志项目中有至少一个已经存在的日志单元。 待上传的日志:logItem,在使用SDK前,需要确保日志已按照特定格式组织。 参数 参数类型 描述 是否必须 endpoint string 域名,详情参考天翼云官网 是 accessKey string AccessKey,简称ak 是 secretKey string SecretKey ,简称sk 是 logProject string 日志项目编码 是 logUnit string 日志单元编码 是 示例代码:SDK日志上传 plaintext using Ctyun.LTS.LOG.Data; using Ctyun.LTS.LOG.Response; namespace Ctyun.LTS.LOG.Example { class SamplePutLogs { public static void Main() { string endpoint "your endpoint"; string accessKey "your accessKey"; string secretKey "your secretKey"; string logProject "your logProject"; string logUnit "your logUnit"; List logItems new List (); for (int i 1; i < 10; ++i) { LogItem logItem new LogItem(); logItem.OriMsg ".NET SDK"; logItem.PushBackContents("errorstring", "invalid operation"); logItem.PushBackContents("content.Int", 12345); logItem.PushBackContents("contentdouble", 3.1415926); logItem.PushBackLabels("usertag", "string"); logItems.Add(logItem); } try { LogClient client new LogClient(endpoint, accessKey, secretKey); for (int i 0; i < 10; i++) { PutLogsResponse response client.PutLogs(logProject, logUnit, logItems); Console.Write(i); response.Print(); } } catch (LogException le) { le.Print(); } catch (Exception e) { Console.WriteLine(e); } } } }