Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8615471
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T05:23:09+00:00 2026-06-12T05:23:09+00:00

The goal is to create logging class and use RavenDB for storage. I originally

  • 0

The goal is to create logging class and use RavenDB for storage. I originally wanted to use NLog, which doesn’t come with RavenDb target but one can easily add it. I did that too but my target was not behaving as intended, I was spinning my wheels trying to figure it out and finally decided to create my own service.

My intention is also to inject this logging service into clients using StructureMap. Here is my initial SM configuration:

x.For<ILogger>().Use<Logger>()
     .Ctor<IDocumentStore>("store").Is(c => c.GetInstance<IDocumentStore>())
     .Ctor<ILogEntry>("logEntry").Is(c => c.GetInstance<ILogEntry>())
     .Ctor<ILogLevelConfig>("logLevelConfig")
     .Is(c => c.GetInstance<ILogLevelConfig>());

x.For<IDocumentStore>()
     .Singleton()
     .Use(() => new DocumentStore { Url="http://localhost:8080/" })
     .OnCreation<IDocumentStore>(c => c.Initialize());

// ILogEntry is implemented by a class, which will eventually be saved in Raven
// ILogLevelConfig is used for configuration purposes

Here is simplified version of the Logger:

public class Logger : ILogger
{
    private readonly ILogEntry _logEntry;
    private readonly IDocumentStore _store;
    private readonly ILogLevelConfig _logLevelConfig;

    public Logger(IDocumentStore store, ILogEntry logEntry, ILogLevelConfig logLevelConfig)
    {
        _logEntry = logEntry;
        _logEntry.TimeStamp = new DateTimeOffset(DateTime.UtcNow);
        _logLevelConfig = logLevelConfig;
        _store = store;
    }

    public void Info(string message, string userId = null)
    {
        if (!_logLevelConfig.IsAllEnabled && !_logLevelConfig.IsInfoEnabled) return;
        _logEntry.LogLevel = LogLevel.Info;
        _logEntry.Message = message;
        _logEntry.UserIdentity = userId;
        Write();
    }

    private void Write()
    {
        using(var session = _store.OpenSession())
        {
            session.Store(_logEntry);
            session.SaveChanges();
        }
    }

Now, let’s simulate injecting the Logger into some client:

var logger = ObjectFactory.GetInstance<ILogger>();
logger.Info("info 1");
logger.Info("info 2");

Questions:

  1. The way Write() is implemented logger will hit the database twice [for ‘info 1’ and then for ‘info 2’. This is going to be extremely chatty approach if I decide to be very detailed with my logging. What can I do collect all my logger.Info(...) into one and then have the session.SaveChanges() be called once and save all my entries in one go?
  2. When I substitute IDocumentStore implementation like this:
    x.For<IDocumentStore>().Singleton().Use(() => new EmbeddableDocumentStore { RunInMemory = true, UseEmbeddedHttpServer = true }).OnCreation<IDocumentStore>(c => c.Initialize()); then only the second call to logger.Info(..) gets actually saved in the database. Why?
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T05:23:10+00:00Added an answer on June 12, 2026 at 5:23 am

    One issue with your object model is that a ILogEntry instance is tied to the ILogger instance instead of being created for each log request as it should be. If you take a look at how NLog or log4net are implemented you will see that they create a corresponding log entry instance for every log request.

    1. You will see in typical logging/tracing implementations the notion of a Flush. This is what “flushes” log entries which have not yet been flushed. This allows the batching of several log entries. Again, existing logging implementations have this notions already implemented so you only have to override an existing class. For example NLog has a BufferingWrapper target for this exact purpose.

    2. This may be resolved by updating your object model as described above.

    Overall, I would try to extend an existing logging framework with a RavenDB target/appender instead of trying to roll your own. Logging is something that works well as a framework and you can learn quite a bit about logging practices in general by working with them.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The goal is to create a mock class which behaves like a db resultset.
My goal is to create a trait that a case class can extend, which
My goal is to create a C# winform application which has rounded panel, rounded
Goal To create an array of Model’s, managed by an ArrayController (ArrayProxy). Requirements Use
The goal is to create a program which will effectively let the user create
GOAL: Create element which will display current big image and few thumbnails. When somebody
My goal is to create (or use existing) an InputStream implementation (say, MergeInputStream) that
Goal: to create a percentage column based off the values of calculated columns. Here's
Duplicate: PHP validation/regex for URL My goal is create a PHP regex for website
I am very new to Json and my goal to create the Json output

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.