Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
*.user
obj/
bin/
.vs/
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,23 @@ Isolate per application in a single Elmah store
<errorLog type="Elmah.AzureTableStorage.AzureTableStorageErrorLog, Elmah.AzureTableStorage"
connectionString="UseDevelopmentStorage=true" applicationName="MyApp" />

By application setting:

<errorLog type="Elmah.AzureTableStorage.AzureTableStorageErrorLog, Elmah.AzureTableStorage"
connectionString="UseDevelopmentStorage=true" applicationNameAppKey="ApplicationName" />

Make sure you add an element under the `appSettings` element.

### Table Name

Set a custom table name (defaults to "Elmah"):

<errorLog type="Elmah.AzureTableStorage.AzureTableStorageErrorLog, Elmah.AzureTableStorage"
connectionString="UseDevelopmentStorage=true" tableName="MyCustomElmahTable" />

By application setting:

<errorLog type="Elmah.AzureTableStorage.AzureTableStorageErrorLog, Elmah.AzureTableStorage"
connectionString="UseDevelopmentStorage=true" tableNameAppKey="ElmahTableName" />

Make sure you add an element under the `appSettings` element.
8 changes: 5 additions & 3 deletions src/Elmah.AzureTableStorage/AzureTableStorageErrorLog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,11 @@ public AzureTableStorageErrorLog(IDictionary config)
// Get custom table name for storage and validate
//

var tableName = config.Find("tableName", DefaultTableName);
var tableName = ElmahHelper.GetTableName(config);
if (tableName.Length == 0)
tableName = DefaultTableName;

if(!Regex.IsMatch(tableName, TableValidationRegex))
if (!Regex.IsMatch(tableName, TableValidationRegex))
throw new ApplicationException("Name for table in Azure Table Storage is not a valid name.");

var cloudStorageAccount = CloudStorageAccount.Parse(connectionString);
Expand All @@ -59,7 +61,7 @@ public AzureTableStorageErrorLog(IDictionary config)
// per-application isolation over a single store.
//

var appName = config.Find("applicationName", string.Empty);
var appName = ElmahHelper.GetApplicationName(config);

if (appName.Length > MaxAppNameLength)
{
Expand Down
40 changes: 40 additions & 0 deletions src/Elmah.AzureTableStorage/ElmahHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,45 @@ public static string GetConnectionString(IDictionary config)
? CloudConfigurationManager.GetSetting(connectionStringAppKey)
: string.Empty;
}

public static string GetApplicationName(IDictionary config)
{
// Check for application name
var applicationName = config.Find("applicationName", string.Empty);
if (applicationName.Length > 0)
return applicationName;

// If not found then check for <appSettings> Key
var applicationNameAppKey = config.Find("applicationNameAppKey", string.Empty);
if (applicationNameAppKey.Length > 0)
{
applicationName = CloudConfigurationManager.GetSetting(applicationNameAppKey);

if (applicationName == null)
return string.Empty;
}

return applicationName;
}

public static string GetTableName(IDictionary config)
{
// Check for table name
var tableName = config.Find("tableName", string.Empty);
if (tableName.Length > 0)
return tableName;

// If not found then check for <appSettings> Key
var tableNameAppKey = config.Find("tableNameAppKey", string.Empty);
if (tableNameAppKey.Length > 0)
{
tableName = CloudConfigurationManager.GetSetting(tableNameAppKey);

if (tableName == null)
return string.Empty;
}

return tableName;
}
}
}