Skip to content

Commit

Permalink
Initial import of Couchbase ELMAH provider with sample app
Browse files Browse the repository at this point in the history
  • Loading branch information
jzablocki committed Jul 23, 2012
1 parent a8bf12b commit d366082
Show file tree
Hide file tree
Showing 168 changed files with 153,278 additions and 2 deletions.
32 changes: 30 additions & 2 deletions README.md
@@ -1,4 +1,32 @@
elmah-couchbase
===============
===========================

Couchbase provider for ELMAH
Logging provider for using Couchbase Server 2.0 with ELMAH.

#Usage

##Configure the Couchbase .NET Client Library

<section name="couchbase" type="Couchbase.Configuration.CouchbaseClientSection, Couchbase" />

<couchbase>
<documentNameTransformer type="Couchbase.Configuration.DevelopmentModeNameTransformer, Couchbase" />
<httpClientFactory type="Couchbase.HammockHttpClientFactory, Couchbase" />
<servers bucket="default">
<add uri="http://127.0.0.1:8091/pools" />
</servers>
</couchbase>

##Configure elmah-couchbase

<elmah>
<errorLog type="Elmah.Couchbase.CouchbaseErrorLog, Elmah.Couchbase" couchbaseConfigSection="<other-than-default-couchbase-section-name>" />
</elmah>

To learn how to configure multiple buckets, see http://www.couchbase.com/wiki/display/couchbase/Couchbase+.NET+Client+Library.

#Notes

Couchbase Server 2.0 required. Developer preview version of .NET Client Library for Couchbase included in "lib" directory.

Be sure to deploy the view found in CouchbaseErrorLog.json at the root of the provider.
Binary file added lib/Couchbase/Couchbase.dll
Binary file not shown.
Binary file added lib/Couchbase/Couchbase.pdb
Binary file not shown.
Binary file added lib/Couchbase/Enyim.Caching.dll
Binary file not shown.
Binary file added lib/Couchbase/Enyim.Caching.pdb
Binary file not shown.
Binary file added lib/Couchbase/Hammock.dll
Binary file not shown.
Binary file added lib/Couchbase/Hammock.pdb
Binary file not shown.
Binary file added lib/Couchbase/Newtonsoft.Json.dll
Binary file not shown.
Binary file added lib/Couchbase/Newtonsoft.Json.pdb
Binary file not shown.
7,320 changes: 7,320 additions & 0 deletions lib/Couchbase/Newtonsoft.Json.xml

Large diffs are not rendered by default.

48 changes: 48 additions & 0 deletions src/Elmah.Couchbase/CouchbaseClientFactory.cs
@@ -0,0 +1,48 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Couchbase;
using Couchbase.Configuration;
using System.Configuration;

namespace Elmah.Couchbase
{
public static class CouchbaseClientFactory
{
public static CouchbaseClient CreateCouchbaseClient(string couchbaseConfigSection = null)
{
if (couchbaseConfigSection != null)
{
var config = ConfigurationManager.GetSection(couchbaseConfigSection) as ICouchbaseClientConfiguration;
if (config == null)
throw new ArgumentException("Couchbase config section " + couchbaseConfigSection + " not found.");

return new CouchbaseClient(config);
}

return new CouchbaseClient();
}
}
}

#region [ License information ]
/* ************************************************************
*
* @author Couchbase <info@couchbase.com>
* @copyright 2012 Couchbase, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* ************************************************************/
#endregion
146 changes: 146 additions & 0 deletions src/Elmah.Couchbase/CouchbaseErrorLog.cs
@@ -0,0 +1,146 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Couchbase;
using System.Collections;
using Couchbase.Configuration;
using Elmah;
using Enyim.Caching.Memcached;
using Newtonsoft.Json;

namespace Elmah.Couchbase
{
/// <summary>
/// ErrorLog implementation using Couchbase Server 2.0 as backing store.
/// </summary>
public class CouchbaseErrorLog : ErrorLog
{
private static CouchbaseClient _client;

/// <summary>
/// Initialize new instance of CouchbaseClient using either default config
/// or specified configuration name
/// </summary>
public CouchbaseErrorLog(IDictionary config)
{
if (config == null)
throw new ArgumentNullException("config");

if (_client == null)
{
if (config.Contains("couchbaseConfigSection"))
{
_client = CouchbaseClientFactory.CreateCouchbaseClient(config["couchbaseConfigSection"] as string);
}
else
{
_client = CouchbaseClientFactory.CreateCouchbaseClient();
}

if (config.Contains("applicationName"))
{
ApplicationName = config["applicationName"] as string;
}
}
}

/// <summary>
/// Get error log entry by id
/// </summary>
public override ErrorLogEntry GetError(string id)
{
if (string.IsNullOrEmpty(id))
throw new ArgumentNullException("id");

Guid errorGuid;
try
{
errorGuid = new Guid(id);
}
catch (FormatException e)
{
throw new ArgumentException(e.Message, "id", e);
}

var errorJson = _client.Get<string>(id);
var error = JsonConvert.DeserializeObject<Error>(errorJson);
return new ErrorLogEntry(this, id, error);
}

/// <summary>
/// Get list of errors for view in Elmah web viewer
/// </summary>
public override int GetErrors(int pageIndex, int pageSize, IList errorEntryList)
{
if (pageIndex < 0)
throw new ArgumentOutOfRangeException("pageIndex", pageIndex, null);

if (pageSize < 0)
throw new ArgumentOutOfRangeException("pageSize", pageSize, null);

var skip = pageSize * pageIndex;

//this is NOT the most efficient way to page in Couchbase/CouchDB, but is necessary because
//there is no way to keep state of the startkey between requests
//see http://www.couchbase.com/docs/couchbase-manual-2.0/couchbase-views-writing-querying-pagination.html
//for more information
var view = _client.GetView("errors", "by_date").Descending(true).Skip(skip).Limit(pageSize);

foreach (var item in view)
{
var errorLogEntry = GetError(item.ItemId);
errorEntryList.Add(errorLogEntry);
}

return view.TotalRows;
}

/// <summary>
/// Log an error
/// </summary>
public override string Log(Error error)
{
if (error == null)
throw new ArgumentNullException("error");

var key = Guid.NewGuid().ToString();
_client.Store(StoreMode.Set, key, JsonConvert.SerializeObject(error));

return key;
}

/// <summary>
/// Name displayed in ELMAH viewer
/// </summary>
public override string Name
{
get
{
return "Couchbase Server Error Log";
}
}

}
}

#region [ License information ]
/* ************************************************************
*
* @author Couchbase <info@couchbase.com>
* @copyright 2012 Couchbase, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* ************************************************************/
#endregion
6 changes: 6 additions & 0 deletions src/Elmah.Couchbase/CouchbaseErrorLog.json
@@ -0,0 +1,6 @@
//view code for Elmah viewer. Must be named "by_date" and located in design document named "errors" without the quotes.
function (doc) {
if (doc.Exception) {
emit(doc.Time, null);
}
}
73 changes: 73 additions & 0 deletions src/Elmah.Couchbase/Elmah.Couchbase.csproj
@@ -0,0 +1,73 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{BAA4BB41-7894-4C7F-98E1-3921FE4FE675}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Elmah.Couchbase</RootNamespace>
<AssemblyName>Elmah.Couchbase</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Couchbase, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\lib\Couchbase\Couchbase.dll</HintPath>
</Reference>
<Reference Include="Elmah">
<HintPath>packages\elmah.corelibrary.1.2.2\lib\Elmah.dll</HintPath>
</Reference>
<Reference Include="Enyim.Caching, Version=2.12.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\lib\Couchbase\Enyim.Caching.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json">
<HintPath>packages\Newtonsoft.Json.4.5.7\lib\net40\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="CouchbaseClientFactory.cs" />
<Compile Include="CouchbaseErrorLog.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="CouchbaseErrorLog.json" />
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
2 changes: 2 additions & 0 deletions src/Elmah.Couchbase/Elmah.Couchbase.csproj.DotSettings.user
@@ -0,0 +1,2 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/Housekeeping/ProjectSettingsUpgraded/IsUpgraded/@EntryValue">True</s:Boolean></wpf:ResourceDictionary>
31 changes: 31 additions & 0 deletions src/Elmah.Couchbase/Elmah.Couchbase.sln
@@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Elmah.Couchbase", "Elmah.Couchbase.csproj", "{BAA4BB41-7894-4C7F-98E1-3921FE4FE675}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ElmahCouchbaseSample", "..\ElmahCouchbaseSample\ElmahCouchbaseSample.csproj", "{7F2B73D5-6AD3-4727-B47A-B16FEEF7C41D}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{5813B801-2877-4F71-BD2E-FBF1856C8137}"
ProjectSection(SolutionItems) = preProject
..\..\README.md = ..\..\README.md
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{BAA4BB41-7894-4C7F-98E1-3921FE4FE675}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BAA4BB41-7894-4C7F-98E1-3921FE4FE675}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BAA4BB41-7894-4C7F-98E1-3921FE4FE675}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BAA4BB41-7894-4C7F-98E1-3921FE4FE675}.Release|Any CPU.Build.0 = Release|Any CPU
{7F2B73D5-6AD3-4727-B47A-B16FEEF7C41D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7F2B73D5-6AD3-4727-B47A-B16FEEF7C41D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7F2B73D5-6AD3-4727-B47A-B16FEEF7C41D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7F2B73D5-6AD3-4727-B47A-B16FEEF7C41D}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
2 changes: 2 additions & 0 deletions src/Elmah.Couchbase/Elmah.Couchbase.sln.DotSettings.user
@@ -0,0 +1,2 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/Housekeeping/SolutionSettingsUpgraded/IsUpgraded/@EntryValue">True</s:Boolean></wpf:ResourceDictionary>
Binary file added src/Elmah.Couchbase/Elmah.Couchbase.suo
Binary file not shown.
36 changes: 36 additions & 0 deletions src/Elmah.Couchbase/Properties/AssemblyInfo.cs
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Elmah.Couchbase")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Elmah.Couchbase")]
[assembly: AssemblyCopyright("Copyright © 2012")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("1601fc5d-5c30-4993-ae96-6f7bcfc3221a")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
Binary file not shown.

0 comments on commit d366082

Please sign in to comment.