public static void Main(string[] args) { //while (!Debugger.IsAttached) { // Thread.Sleep(1000); //} var configuration = new ConfigurationBuilder() .AddCommandLine(args) .Build(); var loggerFactory = new LoggerFactory() .AddDebug() .AddConsole(LogLevel.Trace); var startupOptions = configuration.GetStartupOptions(); if (startupOptions != null && startupOptions.IsService) { loggerFactory.AddEventLog(new EventLogSettings { Filter = (_, logLevel) => logLevel >= LogLevel.Warning, SourceName = Resources.Text_ServiceName }); } configuration = Startup.LoadConfiguration(loggerFactory, configuration.GetValue <string>("config"), args); var loggingOptions = configuration.GetLoggingOptions(); var name = startupOptions != null ? startupOptions.Name : "RTVS"; var logFolder = loggingOptions != null ? loggingOptions.LogFolder : Environment.GetEnvironmentVariable("TEMP"); loggerFactory.AddFile(name, logFolder); var webHost = new WebHostBuilder() .ConfigureServices(s => s.AddSingleton(configuration)) .UseLoggerFactory(loggerFactory) .UseConfiguration(configuration) .UseContentRoot(Directory.GetCurrentDirectory()) .UseKestrel() .UseStartup <WindowsStartup>() .Build(); if (startupOptions != null && startupOptions.IsService) { ServiceBase.Run(new BrokerService(webHost)); } else { try { webHost.Run(); } catch (Exception ex) { ex.HandleWebHostStartExceptions(webHost.Services.GetService <IServiceProvider>(), true); } } }
public static ILogger GetProductionLogger() { var lf = new LoggerFactory(); var els = new EventLogSettings { LogName = "HOLMS", SourceName = "PBXConnector" }; lf.AddEventLog(els); return(lf.CreateLogger("Scheduler")); }
private static ILogger GetLogger() { var lf = new LoggerFactory(); var els = new EventLogSettings { LogName = "HOLMS", SourceName = "Scheduler" }; lf.AddEventLog(els); return(lf.CreateLogger("Scheduler")); }
public static IHostBuilder CreateHostBuilder(string[] args) => Host.CreateDefaultBuilder(args) .UseWindowsService() .ConfigureLogging(LoggerFactory => { LoggerFactory.AddEventLog(); }) .ConfigureServices((hostContext, services) => { services.AddHostedService <Worker>(); services.Add(new ServiceDescriptor(typeof(FileSystemWatcher), new FileSystemWatcher())); services.Add(new ServiceDescriptor(typeof(TcpClient), new TcpClient())); });
public Program() { // A dependency injection based application would get ILoggerFactory injected instead. // Create a logger factory with filter settings that can be applied across all logger providers. var factory = new LoggerFactory() .WithFilter(new FilterLoggerSettings { { "Microsoft", LogLevel.Warning }, { "System", LogLevel.Warning }, { "SampleApp.Program", LogLevel.Debug } }); // getting the logger immediately using the class's name is conventional _logger = factory.CreateLogger <Program>(); // providers may be added to an ILoggerFactory at any time, existing ILoggers are updated #if !NETCOREAPP1_0 factory.AddEventLog(); #endif // How to configure the console logger to reload based on a configuration file. // // var loggingConfiguration = new ConfigurationBuilder() .AddJsonFile(source => { source.Path = "logging.json"; source.ReloadOnChange = true; }) .Build(); factory.AddConsole(loggingConfiguration); // How to configure the console logger to use settings provided in code. // // //var settings = new ConsoleLoggerSettings() //{ // IncludeScopes = true, // Switches = // { // ["Default"] = LogLevel.Debug, // ["Microsoft"] = LogLevel.Information, // } //}; //factory.AddConsole(settings); // How to manually wire up file-watching without a configuration file // // //factory.AddConsole(new RandomReloadingConsoleSettings()); }
public Program() { // a DI based application would get ILoggerFactory injected instead var factory = new LoggerFactory(); // getting the logger immediately using the class's name is conventional _logger = factory.CreateLogger(typeof(Program).FullName); // providers may be added to an ILoggerFactory at any time, existing ILoggers are updated #if !DNXCORE50 factory.AddNLog(new global::NLog.LogFactory()); factory.AddEventLog(); #endif factory.AddConsole(); factory.AddConsole((category, logLevel) => logLevel >= LogLevel.Critical && category.Equals(typeof(Program).FullName)); }
// Eventlog static void LoggingDemo6(string scopeName = null) { Debugger.Break(); // Logger Factory konfigurieren ILoggerFactory loggerFactory = new LoggerFactory() .AddConsole() .AddDebug(); // Eventlog gibt es nur unter Windows if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { loggerFactory.AddEventLog(LogLevel.Critical); } ILogger logger = loggerFactory.CreateLogger <Program>(); demoLogging(logger, scopeName); }
public Program() { // a DI based application would get ILoggerFactory injected instead var factory = new LoggerFactory(); // getting the logger immediately using the class's name is conventional _logger = factory.CreateLogger <Program>(); // providers may be added to an ILoggerFactory at any time, existing ILoggers are updated #if !DNXCORE50 factory.AddNLog(new global::NLog.LogFactory()); factory.AddEventLog(); #endif // How to configure the console logger to reload based on a configuration file. // // var loggingConfiguration = new ConfigurationBuilder().AddJsonFile("logging.json").Build(); factory.AddConsole(loggingConfiguration); loggingConfiguration.ReloadOnChanged("logging.json"); // How to configure the console logger to use settings provided in code. // // //var settings = new ConsoleLoggerSettings() //{ // IncludeScopes = true, // Switches = // { // ["Default"] = LogLevel.Verbose, // ["Microsoft"] = LogLevel.Information, // } //}; //factory.AddConsole(settings); // How to manually wire up file-watching without a configuration file // // //factory.AddConsole(new RandomReloadingConsoleSettings()); }