I just did something similar on the weekend. I ended up creating 1 table called "LogEvents" and used the provider key to separate the different types of events and log dates (for example, ProviderKey = "20111121_LoginEvent" when someone logged in November 21).
For me, queries can be easily performed by date / type and display the result on the admin page
Not sure if this is the best way, but it seems to work for me. I searched google but couldn't find anything that really did this.
Update 1: The class I'm using is called LogEvent:
public class LogEntry : TableServiceEntity { public LogEntry(string logType) { if (LogType == null || LogType.Length == 0) { if (logType.Length > 0) LogType = logType; else LogType = "Default"; } PartitionKey = string.Format("{0}_{1}", LogType, DateTime.UtcNow.ToString("yyyyMMdd")); RowKey = string.Format("{0:10}_{1}", DateTime.MaxValue.Ticks - DateTime.Now.Ticks, Guid.NewGuid()); } public LogEntry() { } public string Message { get; set; } public DateTime LogDateTime { get; set; } public string LogType { get; set; } }
I just create a new instance and set the properties:
LogEntry le = new LogEntry("Default") { Message = "Default Page Loaded", LogDateTime=DateTime.Now }; LogEntryDataSource ds = new LogEntryDataSource(); ds.AddLogEntry(le);
To return the data again, I just use the standard Linq query and pass in the date and LogType:
public IEnumerable<LogEntry> GetLogEntries(string eventType, DateTime logDate) { var results = from g in this.context.LogEntry where g.PartitionKey == String.Format("{0}_{1}", eventType, logDate.ToString("yyyyMMdd")) select g; return results; }
Probably the best way, but it was pretty easy to set up, and it works for me.
source share