DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

.NET Couchbase Client Instrumentation

Don Pinto user avatar by
Don Pinto
·
Mar. 07, 13 · Interview
Like (0)
Save
Tweet
Share
2.50K Views

Join the DZone community and get the full member experience.

Join For Free

Curator's Note: The content of this article was originally authored by John Zablocki over at the Couchbase blog .

The .NET Client Library provides detailed error information by way of its IOperationResult interface.  To find out why a store operation failed, use ExecuteStore instead of Store.

var result = client.ExecuteStore(StoreMode.Add, "key", "value");
if (! result.Success)
{
    Console.WriteLine("Operation failed with message {0} and status code {1}", result.Message, result.StatusCode);
}
While the IOperationResult value that's returned provides status codes, caught exceptions and error messages, there are situations where detailed logging is necessary to diagnose a persistent problem.

With the recent 1.2.2 release of the .NET Client Library for Couchbase, logging assemblies are included by default in both the Nuget package and the zip with the latest binaries.  Out of the box, Couchbase (and its dependency Enyim.Caching) supports log4net and NLog logging. 

It's pretty straightforward to enable logging with Couchbase, but you do need to know the basics of configuring log4net or NLog to get going.  If you're just starting out with Couchbase and ASP.NET, it would be useful to see logging details without having to learn another framework, even if minimal.  Fortunately, if you're using the diagnostics tool Glimpse in your ASP.NET application, you can turn on logging quite easily.

If you're not familiar with Glimpse, the common analogy is "Firebug for ASP.NET."  Once you install the NuGet package for Glimpse and enable the framework, you get a diagnostics window in your application that provides you with a view of the request as it was executed on the server.  You can see your web.config settings, environment details, routes, server variables and several other aspects of your executing web application. 

Nik and Anthony, who created the open source Glimpse project (supported now by Redgate) have created a powerful extensibility model.  Plugging into the Glimpse UI to provide instrumentation details for a library is as simple as implementing the ITab interface (or extending TabBase). 

The Enyim.Caching dependency in the Couchbase client defines ILog and ILogFactory interfaces, which when implemented may be used to provide a custom logging provider for capturing Couchbase instrumentation details.  For my new CouchbaseLabs project Couchbase.Glimpse, I have created a new logger that will capture per-request logs and send the output to Glimpse. 

To get started, install and enable Glimpse.  Once you've done that, install the CouchbaseGlimpse extension.  The NuGet package will add the necessary configuration for you.  You can also grab the source from GitHub.  If you go the source code route, you'll need to include the config section below.

<configuration>
  <configSections>
    <sectionGroup name="enyim.com">
      <section name="log" type="Enyim.Caching.Configuration.LoggerSection, Enyim.Caching" />
    </sectionGroup>
     ...
  </configSections>
  <enyim.com>
    <log factory="Couchbase.Glimpse.Logging.GlimpseLogFactory, Couchbase.Glimpse" />
  </enyim.com>
</configuration>

You'll need to enable logging to start capturing details from the client.  Somewhere in your application, probably Application_Start, you'll need to call the Configure method on GlimpseLogger.

var config = new GlimpseLogConfiguration { IsDebugEnabled = true };
GlimpseLogger.Configure(config);

Logging levels are cumulative, so enabling debug enables all other levels.  You can also capture specific loggers (logs per class) by adding log names to the white list.  The configuration below will output logs originating only in the PooledSocket and ConfigHelper classes.

var config = new GlimpseLogConfiguration { IsDebugEnabled = true };
config.SourceWhiteList.AddRange(new[] { "PooledSocket", "ConfigHelper" });
GlimpseLogger.Configure(config);

Once you've built your app to include the new Couchbase tab in Glimpse, navigate to a page where the Couchbase client is being used.  You should see something similar to the screen capture below.

Couchbase Glimpse Tab

You'll find that when the client is first bootstrapping, it's a bit chatty with debug logs.  However, if you're having a problem connecting to your cluster, there's probably valuable information available to you, including the cluster config (which you can see as JSON in the screen capture above). 

The GlimpseLogger isn't persisting its logs, so if you need to capture diagnostic information beyond a request, you'll need to use log4net or NLog.

The GitHub repo contains a copy of the .NET beer sample app with Glimpse enabled.  Clone that repo and run the app to get a quick sense of how the plugin works.



Instrumentation (computer programming)

Published at DZone with permission of Don Pinto, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Web Application Architecture: The Latest Guide
  • Exploring the Benefits of Cloud Computing: From IaaS, PaaS, SaaS to Google Cloud, AWS, and Microsoft
  • Top Authentication Trends to Watch Out for in 2023
  • Cloud Native London Meetup: 3 Pitfalls Everyone Should Avoid With Cloud Data

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: