Log4Net Azure Storage Appender

 Install

Add To project via NuGet:

Right click on a project and click 'Manage NuGet Packages'.
Search for 'log4net.Appender.Azure' and click 'Install'.

Configuration

Table Storage

Every log entry is stored in a separate row.

<appender name="AzureTableAppender" type="log4net.Appender.AzureTableAppender, log4net.Appender.Azure">
   <param name="TableName" value="testLoggingTable"/>
   <!-- You can either specify a connection string or use the ConnectionStringName property instead -->
   <param name="ConnectionString" value="UseDevelopmentStorage=true"/>
   <!--<param name="ConnectionStringName" value="GlobalConfigurationString" />-->
   <!-- You can specify this to make each LogProperty as separate Column in TableStorage, 
Default: all Custom Properties were logged into one single field -->
   <param name="PropAsColumn" value="true" />
   <param name="PartitionKeyType" value="LoggerName" />
 </appender>

TableName:
Name of the table in Table Storage

ConnectionString:
the full Azure Storage connection string

ConnectionStringName:
Name of a connection string specified under connectionString

PropAsColumn(optional):
Default: all properties were written in a single field(default).
If you specifiy this with the value true then each custom log4net property is logged as separate column/field in the table.
Remember that Table storage has a Limit of 255 Properties.
PartitionKeyType(optional):
Default "LoggerName": (each logger gets his own partition in Table Storage)
"DateReverse": order by Date Reverse 

BlobStorage
Every log Entry is stored as separate XML file.

<appender name="AzureBlobAppender" type="log4net.Appender.AzureBlobAppender, log4net.Appender.Azure">
  <param name="ContainerName" value="testloggingblob"/>
  <param name="DirectoryName" value="logs"/>
  <!-- You can either specify a connection string or use the ConnectionStringName property instead -->
  <param name="ConnectionString" value="UseDevelopmentStorage=true"/>
  <!--<param name="ConnectionStringName" value="GlobalConfigurationString" />-->
</appender>

ContainerName:
Name of the container in Blob Storage
DirectoryName:
Name of the folder in the specified container
ConnectionString:
the full Azure Storage connection string
ConnectionStringName:
Name of a connection string specified under connectionString
AppendBlobStorage
Every log Entry is stored as separate XML file.

<appender name="AzureAppendBlobAppender" type="log4net.Appender.AzureAppendBlobAppender, log4net.Appender.Azure">
  <param name="ContainerName" value="testloggingblob"/>
  <param name="DirectoryName" value="logs"/>
  <!-- You can either specify a connection string or use the ConnectionStringName property instead -->
  <param name="ConnectionString" value="UseDevelopmentStorage=true"/>
  <!--<param name="ConnectionStringName" value="GlobalConfigurationString" />-->
</appender>

ContainerName:
Name of the container in Blob Storage
DirectoryName:
Name of the folder in the specified container
ConnectionString:
the full Azure Storage connection string
ConnectionStringName:
Name of a connection string specified under connectionString

Post a Comment

0 Comments