Example #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);
        }