I am currently creating a prototype of a custom Log4Net application that will store information about all exceptions that occur in a project in an Azure table. The table is created based on the model defined in the "LogEntry" class. Since this is a prototype web application, at the moment I have created a button that throws an exception to start the registrar, and I am following this as a guide:
http://www.kongsli.net/nblog/2011/08/15/log4net-writing-log-entries-to-azure-table-storage/
However, when an exception is thrown and a log is created, the table is not created correctly. Instead of creating a table based on my LogEntry class, it only generates what I assume as the default values ββfor the TableServiceContext for "PartitionKey", "RowKey" and "TimeStamp". As a result, the logger does not execute any records in the table.
Below are some excerpts from my project:
LogEntry.cs
public class LogEntry : TableServiceEntity { public LogEntry() { var now = DateTime.UtcNow;
LogServiceContext.cs
internal class LogServiceContext : TableServiceContext { public LogServiceContext(string baseAddress, StorageCredentials credentials) : base(baseAddress, credentials) { } internal void Log(LogEntry logEntry) { AddObject("LogEntries", logEntry); SaveChanges(); } public IQueryable<LogEntry> LogEntries { get { return CreateQuery<LogEntry>("LogEntries"); } } }
And extracting from the appender class itself:
// Create a new LogEntry and store all necessary details. // All writing to log is done asynchronically to prevent the write slowing down request handling. Action doWriteToLog = () => { try { _ctx.Log(new LogEntry { CreatedDateTime = DateTime.Now, UserName = loggingEvent.UserName, IPAddress = userIPAddress, Culture = userCulture, OperatingSystem = userOperatingSystem, BrowserVersion = userCulture, ExceptionLevel = loggingEvent.Level, ExceptionDateTime = loggingEvent.TimeStamp, ExceptionMessage = loggingEvent.RenderedMessage, ExceptionStacktrace = Environment.StackTrace, AdditionalInformation = loggingEvent.RenderedMessage }); } catch (DataServiceRequestException e) { ErrorHandler.Error(string.Format("{0}: Could not wring log entry to {1}: {2}", GetType().AssemblyQualifiedName, _tableEndpoint, e.Message)); } }; doWriteToLog.BeginInvoke(null, null);
I am happy to provide any additional information and I can package the solution if someone wants to see the classes in full form. Any help would be greatly appreciated!