-
Notifications
You must be signed in to change notification settings - Fork 68
/
LoggingEventExtensions.cs
34 lines (32 loc) · 1.29 KB
/
LoggingEventExtensions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
using System;
using log4net.Core;
namespace log4net.Appender
{
internal static class LoggingEventExtensions
{
internal static string MakeRowKey(this LoggingEvent loggingEvent)
{
return string.Format(
"{0:D19}.{1}",
DateTime.MaxValue.Ticks - loggingEvent.TimeStamp.Ticks,
Guid.NewGuid().ToString().ToLower());
}
internal static string MakePartitionKey(this LoggingEvent loggingEvent, PartitionKeyTypeEnum partitionKeyType)
{
switch (partitionKeyType)
{
case PartitionKeyTypeEnum.LoggerName:
return loggingEvent.LoggerName;
case PartitionKeyTypeEnum.DateReverse:
// substract from DateMaxValue the Tick Count of the current hour
// so a Table Storage Partition spans an hour
return string.Format("{0:D19}",
(DateTime.MaxValue.Ticks -
loggingEvent.TimeStamp.Date.AddHours(loggingEvent.TimeStamp.Hour).Ticks + 1));
default:
// ReSharper disable once NotResolvedInText
throw new ArgumentOutOfRangeException("PartitionKeyType", partitionKeyType, null);
}
}
}
}