Skip to content
/ MLog Public

MLog is the simplest .NET library for data logging

License

Notifications You must be signed in to change notification settings

mykeels/MLog

Repository files navigation

MLog

Now with .NET Core Support, MLog is a simple .NET Library for Data Logging in your .NET Apps.

How to Use

Simple Usage

//Task: Create a Log for the creation of a New Student
Mlog.Log log = Mlog.Log.Create<Student>(newStudent);
log.Title = "New Student Created: [" + newStudent.FullName + "]";
log.Description = log.Application + " Data Log for " + title;
Mlog.Manager.Add(log);

Log Relationships

Logs have parent-children relationships using the Parent property of each Log-Item. To Create a Child Log:

//Task: Create a Log for the creation of a New Student's Course
var coursesLog = Mlog.Log.Create<List<Course>>(newStudent.GetCourses());
log.Title = "New Courses added for [" + newStudent.FullName + "]";
log.Description = log.Application + " Data Log for " + title;
log.AddChild(coursesLog);
Mlog.Manager.Add(log);

Log Ip Address

For documentation purposes, you might want to include the IP Address of the User who performs an Action in its Log.

log.IpAddress = MLog.Util.GetIpAddress();

Log Requests and Responses in WebApi programs

    [Route("api/students/add")]
    public Response<Student> Add([FromBody()] Models.User val)
    {
        return MLog.Manager.AddRequestAndResponse<Response<Student>, User>("api-student-add", val, (Student values) =>
        {
            return new Response<Student>("New Student Created", Student.Add(values), true);
        });
    }

Dependencies

Supported Databases

Setup Web.Config

Set the [Application] Field

  <appSettings>
    <add key="mlog-app" value="MlogTests" />
  </appSettings>

Database Connection String

  <connectionStrings>
    <add name="MLog.Properties.Settings.MLogConnectionString" connectionString="Data Source=MYKEELS-PC;Initial Catalog=MLog;User ID=[your db username];Password=[your password]"
        providerName="System.Data.SqlClient" />
  </connectionStrings>

Setup config.json

{
  "appSettings": {
    "mlog-app": "MlogTests",
    "MongoDBUri": "mongodb://localhost:27017",
    "MongoDBName": "MLogTests"
  },
  "connectionStrings": [
    {
      "name": "MLog.Properties.Settings.MLogConnectionString",
      "connectionString": "Data Source=MYKEELS-PC;Initial Catalog=MLog;User ID=mykeels",
      "providerName": "System.Data.SqlClient"
    }
  ]
}

Future Improvements

The dream is to make MLog multi-platform using the .NET Standard, and ensure it is possible to use MLog with the following Databases:

  • SQL Server
  • MongoDB

Also, we need to provide developer-users with a way to configure MLog using Lamda Expressions, so they can make MLog behave in any number of ways to suit their applications.

Enjoying MLog? How you can thank me ...

Follow me on twitter. Star this github repo . Check out my other projects and see if you like them.

Provide useful code critism. I'd love to hear from you, really.

Thanks! Ikechi Michael I.

License

The MIT License. Please see License File for more information.

About

MLog is the simplest .NET library for data logging

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages