MongoLogger example

CSharp · Console

/Program.cs

using System;

using MongoLogger; //<-add
using Serilog;  //<-add
					
public class Program
{
	public static void Main()
	{
		
		//init
		 MongoLogger.MongoLog.Init(
                new MongoLog.AppOption() { AuthorName = "Rolence", ProjectName = "MyTestConsole" },
                new MongoLog.MailNotifyOption()
                {
                    MailList = new string[] { "[email protected]" },
                    MailServer = "smtp.mailgun.org",
                    MailSubjectTemplate = "{0}-Error",
                    NetworkCredential = new System.Net.NetworkCredential() { UserName = "YOURNAME", Password = "PASSWORD" },
                    LogLevel = Serilog.Events.LogEventLevel.Error,
                    BatchPostingLimit = 10
                },
                new MongoLog.MongoOption()
                {
                    MongoDBIp = "YOURIP",
                    CollectionName = "Log",
                    CollectionMB = 5,
                    LogLevel = Serilog.Events.LogEventLevel.Error,
                    BatchPostingLimit = 5,
                    BatchTimePostingLimit = new TimeSpan(0, 0, 5)
                }
            );
		
		
			//start log
            Log.Information("This is test log:{@app},{count}", new { author = "rolence" }, 1);
            Log.Error(new Exception("Test exception"), "This is test error log:{@app},{count}", new { author = "rolence" }, 1);
	}
}
;