/// <summary>
        /// Upload thread
        /// </summary>
        /// <param name="stoppingToken"></param>
        /// <returns></returns>
        public async Task <int> UploadAsync(CancellationToken stoppingToken)
        {
            var lotsize = 200;
            var chunk   = new List <LogRecord>();

            lock (Messages)
            {
                for (var i = 0; i < lotsize && Messages.Count > 0; i++)
                {
                    var ev  = Messages.Dequeue();
                    var rec = new LogRecord
                    {
                        EventTime     = ev.EventUtcTime,
                        Facility      = $"Eventlog.{ev.LogName}",
                        SeverityLevel = ev.Level,
                        Computer      = ev.Computer,
                        HostIP        = null,
                        HostName      = null,
                        SyslogMessage = ev.Message,
                        RecordID      = ev.EventRecordID,
                        EventID       = ev.EventID,
                        User          = ev.User,
                        OpCode        = ev.OpCode,
                        TaskCategory  = ev.TaskCategory,
                        Keywords      = ev.Keywords,
                    };
                    chunk.Add(rec);
                }
            }
            Logger.LogTrace($"{DateTime.Now} : Sending {chunk.Count} records to Azure");

            if (chunk.Count == 0)
            {
                return(10567);
            }
            int a   = 1;
            var emc = new EventMessageConverter();

            foreach (var item in chunk)
            {
                item.SyslogMessage = emc.Convert(item.SyslogMessage);
            }


            var jsonStr      = JsonConvert.SerializeObject(chunk, new IsoDateTimeConverter());
            var datestring   = DateTime.UtcNow.ToString("r");
            var jsonBytes    = Encoding.UTF8.GetBytes(jsonStr);
            var stringToHash = "POST\n" + jsonBytes.Length + "\napplication/json\n" + "x-ms-date:" + datestring + "\n/api/logs";
            var hashedString = BuildSignature(stringToHash, PrimaryKey);
            var signature    = "SharedKey " + WorkspaceID + ":" + hashedString;

            await PostDataAsync(signature, datestring, jsonStr);

            Logger.LogTrace($"---- Sent {chunk.Count} records at {DateTime.Now}", true);

            return(chunk.Count == lotsize ? 23 : 5569);
        }
Example #2
0
        public static string ConvertFrom(string mes)
        {
            var emc = new EventMessageConverter();

            return(emc.Convert(mes));
        }