Skip to content

stemarie/log4net.Azure

Repository files navigation

Stories in Ready #log4net.Azure

Transfer all your logs to the Azure Table or Blob Storage via Appender for log4Net

Install

Add To project via NuGet:

  1. Right click on a project and click 'Manage NuGet Packages'.
  2. 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 (see here).
  • PartitionKeyType(optional):
    Default "LoggerName": (each logger gets his own partition in Table Storage)
    "DateReverse": order by Date Reverse to see the latest items first (How to order elements 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

View Logs

You can take a look on this Site to use one of this tools based on your selected appender.