Example #1
0
        static async Task Main(string[] args)
        {
            try
            {
                #region nlog相關設定
                StaticSetting.SetNlogProperties();  //設定 Nlog Property (會抓Program Name)
                List <LogLevel> levels = new List <LogLevel>()
                {
                    LogLevel.Trace,
                    LogLevel.Error,
                    //LogLevel.Critical
                };
                StaticSetting.SetCustomPrintLogLevel(levels); //要允許印哪些level的log
                StaticSetting.SetNlogConfig();                //設定 Nlog Config
                #endregion

                //setup our DI
                IServiceCollection serviceCollection = new ServiceCollection(); //NUGET: Microsoft.Extensions.DependencyInjection
                IConfiguration     config            = ConfigureServices(serviceCollection);
                ServiceProvider    serviceProvider   = serviceCollection.BuildServiceProvider();

                ILogHelper _loghelper = serviceProvider.GetService <ILogHelper>();

                LogModel model = new LogModel()
                {
                    Name = "測試Name12",
                    //ProgramName = "TestProgramName",
                    ExceptionMessage = "Test ExceptionMessage",
                    //FileName = "",
                    KeyWord         = "hi i m key word.12",
                    ExceptionDetail = "test error detail",
                    LogLevel        = LogLevel.Error
                };
                await _loghelper.DoLog(model);

                Console.WriteLine("Done");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
            Console.WriteLine("Hello World!");
        }