Skip to content

BrammyS/Serilog.Sinks.Mongodb.TimeSeries

Repository files navigation

NuGet NuGet Stargazers Issues MIT License


Logo

Serilog.Sinks.Mongodb.TimeSeries

A simple to use sink for Serilog that saves logs in a Mongodb time series collection.
Explore the docs »

Report Bug · Request Feature

Table of Contents

  1. About The Project
  2. Getting Started
  3. Usage
  4. Contributing
  5. License
  6. Versioning
  7. Acknowledgements

About The Project

Serilog.Sinks.Mongodb.TimeSeries is a nuget package to save all your logs to a time series mongodb collection.
It is super simple to setup! There are only a couple lines needed. Head down to the Installation guide for more info.

Built With

Getting Started

To get a local copy up and running follow these simple steps.

Prerequisites

Installation

Nuget

Serilog.Sinks.Mongodb.TimeSeries is available on NuGet.

Cloning

  1. Clone the repo
    git clone https://github.com/BrammyS/Serilog.Sinks.Mongodb.TimeSeries.git
  2. Build the repo
    dotnet build

Usage

You will need to do the following to add Serilog.Sinks.Mongodb.TimeSeries as a sink in your program.

Default configurations

var client = new MongoClient("mongodb://mongodb0.example.com:27017");
var mongoDatabase = client.GetDatabase("dbName");

Log.Logger = new LoggerConfiguration()
                 .WriteTo.MongoDbTimeSeriesSink(mongoDatabase)
                 .CreateLogger();

Custom configurations

var client = new MongoClient("mongodb://mongodb0.example.com:27017");
var mongoDatabase = client.GetDatabase("dbName");

var configs = new MongoDbTimeSeriesSinkConfig(mongoDatabase)
{
    CollectionName = "Logs",
    TimeSeriesGranularity = TimeSeriesGranularity.Seconds,
    SyncingPeriod = TimeSpan.FromSeconds(10),
    LogsExpireAfter = TimeSpan.FromDays(7),
    MaxCollectionSize = 100 * 1024 * 1024,
    EagerlyEmitFirstEvent = true,
    MaxLogsAmount = 100000,
    BatchSizeLimit = 500,
    QueueLimit = 20000
};

Log.Logger = new LoggerConfiguration()
                 .WriteTo.MongoDbTimeSeriesSink(configs)
                 .CreateLogger();

Contributing

Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

Versioning

Serilog.Sinks.Mongodb.TimeSeries uses Semantic Versioning 2.0.0 for its versioning.

Summary

The versioning will be using the following format: MAJOR.MINOR.PATCH.

  • MAJOR version when you make incompatible API changes,
  • MINOR version when you add functionality in a backwards compatible manner, and
  • PATCH version when you make backwards compatible bug fixes.
  • Additional labels for pre-release and build metadata are available as extensions to the MAJOR.MINOR.PATCH format.

License

Distributed under the MIT License. See LICENSE for more information.

Acknowledgements