Пример #1
0
        /// <summary>
        /// Creates a full populated new <see cref="ApplicationLogEntity"/> from a given <see cref="LogEntry"/>
        /// </summary>
        /// <param name="logEntry"></param>
        /// <param name="formatter"></param>
        /// <returns></returns>
        public static ApplicationLogEntity CreateFromLogEntry(LogEntry logEntry, ILogFormatter formatter)
        {
            Guard.ArgumentNotNull(logEntry, "logEntry");
            ApplicationLogEntity entity = new ApplicationLogEntity
            {
                AppDomainName   = logEntry.AppDomainName,
                ApplicationName = logEntry.ApplicationName,
                Category        = logEntry.Categories.Join(","),
                EventId         = logEntry.EventId,
                MachineName     = Environment.MachineName,
                Message         = logEntry.Message,
                Priority        = logEntry.Priority,
                ProcessId       = logEntry.ProcessId,
                ProcessName     = logEntry.ProcessName,
                Severity        = logEntry.Severity.ToString(),
                ThreadName      = logEntry.ManagedThreadName,
                Title           = logEntry.Title,
                Win32ThreadId   = logEntry.Win32ThreadId
            };

            entity.Timestamp        = new DateTimeOffset(logEntry.TimeStamp, TimeSpan.Zero);
            entity.PartitionKey     = CreatePartitionKey(entity.ApplicationName, entity.Timestamp);
            entity.RowKey           = ApplicationLogEntityManager.CreateRowKey(SortOrder.Descending);
            entity.FormattedMessage = formatter != null?formatter.Format(logEntry) : logEntry.Message;

            return(entity);
        }
        /// <summary>
        /// CloudStorage asynchronous write implementation
        /// </summary>
        /// <param name="logEntry"></param>
        /// <returns></returns>
        protected async Task ExecuteWriteLogAsync(LogEntry logEntry)
        {
            ApplicationLogEntity entity = ApplicationLogEntityManager.CreateFromLogEntry(logEntry, this.Formatter);

            if (entity == null)
            {
                return;
            }

            CloudTable table = GetTableReference();
            await table.CreateIfNotExistsAsync();

            TableOperation insertOperation = TableOperation.Insert(entity);
            await table.ExecuteAsync(insertOperation);
        }
Пример #3
0
 public static ApplicationLogEntity Create(string title, string rawMessage, string formattedMessage, int eventId, string applicationName = "Default", TraceEventType severity = TraceEventType.Error, string category = "General", int priority = 1, string processId = null, string processName = null, string threadName = null, string wind32ThreadId = null)
 {
     return(new ApplicationLogEntity
     {
         AppDomainName = "Unknown AppDomain",
         ApplicationName = applicationName,
         Category = category,
         EventId = eventId,
         FormattedMessage = formattedMessage,
         MachineName = Environment.MachineName,
         Message = rawMessage,
         PartitionKey = CreatePartitionKey(applicationName, DateTimeOffset.UtcNow),
         Priority = priority,
         ProcessId = processId,
         ProcessName = processName,
         RowKey = ApplicationLogEntityManager.CreateRowKey(SortOrder.Descending),
         Severity = severity.ToString(),
         ThreadName = threadName,
         Timestamp = DateTimeOffset.UtcNow,
         Title = title,
         Win32ThreadId = wind32ThreadId
     });
 }