Skip to content

Commit

Permalink
update code
Browse files Browse the repository at this point in the history
  • Loading branch information
Maniceraf committed Dec 4, 2023
1 parent b838978 commit 62c62c7
Showing 1 changed file with 61 additions and 1 deletion.
62 changes: 61 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@ To begin using **Maniceraf.SimpleMongoDbLogger** start by installing the latest
You can install the **Maniceraf.SimpleMongoDbLogger** via [NuGet](https://www.nuget.org/packages/Maniceraf.SimpleMongoDbLogger). Use the Package Manager Console or the .NET CLI:

```bash
dotnet add package Maniceraf.SimpleMongoDbLogger --version 1.0.0-preview-1
dotnet add package Maniceraf.SimpleMongoDbLogger --version 1.0.1
```

## **Usage**

### **Initialization**
Initialize the logger by providing the MongoDB connection string, database name, and collection name:
```csharp
using Maniceraf.SimpleMongoDbLogger;

Expand All @@ -40,6 +43,63 @@ class Program
}
```

### **Dependency Injection**
If you prefer using Dependency Injection:

#### **1. Configure the MongoDB connection in your application's Startup.cs or equivalent:**
```csharp
using Microsoft.Extensions.DependencyInjection;
using MongoDB.Driver;
using MongoDBLogger;

public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
// MongoDB configuration
string connectionString = "...";
string databaseName = "...";
string collectionName = "...";

// Register MongoDBLogger as a service
services.AddSimpleMongoDbLogger(options =>
{
options.ConnectionString = connectionString;
options.DatabaseName = databaseName;
options.CollectionName = collectionName;
});

// Or register MongoDBLogger with another way
services.AddSimpleMongoDbLogger(connectionString, databaseName, collectionName);

// Other service registrations...
}
}
```
#### **2. Inject the ILogger interface where logging is needed:**
```csharp
using MongoDBLogger;

public class SomeClass
{
private readonly IMongoDbLogger _logger;

public SomeClass(IMongoDbLogger logger)
{
_logger = logger;
}

public void SomeMethod()
{
// Log some messages
logger.WriteLog(LogLevel.Info, "This is an informational message");
await logger.WriteLogAsync(LogLevel.Info, "This is an informational message");

// Logging other messages...
}
}
```

## **License**

This library is licensed under the [MIT](https://github.com/Maniceraf/Maniceraf.SimpleMongoDbLogger/blob/master/LICENSE.txt) License.

0 comments on commit 62c62c7

Please sign in to comment.