public FixUsingsFacts()
 {
     _loggerFactory = new LoggerFactory();
     _loggerFactory.AddConsole();
     _logger = _loggerFactory.CreateLogger<FixUsingsFacts>();
     _loader = new TestOmnisharpAssemblyLoader(_logger);
 }
Exemple #2
0
        // This method gets called by the runtime. Use this method to add services to the container
        public void ConfigureServices(IServiceCollection services)
        {
            // Add framework services.
            var sqlLoggerFactory = new LoggerFactory();
            sqlLoggerFactory.AddConsole(Configuration.GetSection("SqlLogging"));

            // Add framework services.
            services.AddApplicationInsightsTelemetry(Configuration);

            services.AddMvc();

            var entityFramework = services;
            entityFramework= entityFramework
                .AddEntityFrameworkSqlServer()
                .AddDbContext<DDDContext>(options =>
                options.UseSqlServer(Configuration["Data:DefaultConnection:ConnectionString"],
                x => x.MigrationsAssembly("DDDCore.Application"))
                .UseLoggerFactory(sqlLoggerFactory));

            //Domain
            services.AddScoped<IClienteService, ClienteService>();

            //infra
            services.AddScoped<IClienteRepository, ClienteRepository>();
            services.AddScoped<DDDContext>();
        }
        public CodingActionsV2Facts()
        {
            _loggerFactory = new LoggerFactory();
            _loggerFactory.AddConsole();
            _logger = _loggerFactory.CreateLogger<CodingActionsV2Facts>();

            _loader = new TestOmnisharpAssemblyLoader(_logger);
        }
        public TaskRunnerTests()
        {
            var lf = new LoggerFactory();
            lf.AddConsole();

            var serviceProvider = new ServiceCollection()
                .AddTransient(_ => new SampleTask(settings))
                .BuildServiceProvider();

            sampleTask = new TaskRunner<SampleTask>(lf, serviceProvider.GetService<IServiceScopeFactory>());
            sampleTask.Interval = TimeSpan.FromSeconds(5);
        }
        public void AspNetCoreLogging_MinLogLevel_Warn()
        {
            var external = new LoggerFactory();
            external.AddConsole(LogLevel.Warning);
            var loggerFactory = new MicrosoftLoggerFactoryAdapter(external);
            var logger = loggerFactory.CreateLogger("cat");

            logger.Should().NotBeNull();
            logger.IsEnabled(Core.Logging.LogLevel.Trace).Should().BeFalse();
            logger.IsEnabled(Core.Logging.LogLevel.Debug).Should().BeFalse();
            logger.IsEnabled(Core.Logging.LogLevel.Information).Should().BeFalse();
            logger.IsEnabled(Core.Logging.LogLevel.Warning).Should().BeTrue();
            logger.IsEnabled(Core.Logging.LogLevel.Error).Should().BeTrue();
            logger.IsEnabled(Core.Logging.LogLevel.Critical).Should().BeTrue();
        }
Exemple #6
0
        public static int Main(string[] args)
        {
            var app = new CommandLineApplication();
            app.Name = "dotnet-projectmodel-server";
            app.Description = ".NET Project Model Server";
            app.FullName = ".NET Design Time Server";
            app.Description = ".NET Design Time Server";
            app.HelpOption("-?|-h|--help");

            var verbose = app.Option("--verbose", "Verbose ouput", CommandOptionType.NoValue);
            var hostpid = app.Option("--host-pid", "The process id of the host", CommandOptionType.SingleValue);
            var hostname = app.Option("--host-name", "The name of the host", CommandOptionType.SingleValue);
            var port = app.Option("--port", "The TCP port used for communication", CommandOptionType.SingleValue);

            app.OnExecute(() =>
            {
                var loggerFactory = new LoggerFactory();
                loggerFactory.AddConsole(verbose.HasValue() ? LogLevel.Debug : LogLevel.Information);

                var logger = loggerFactory.CreateLogger<Program>();

                if (!MonitorHostProcess(hostpid, logger))
                {
                    return 1;
                }

                var intPort = CheckPort(port, logger);
                if (intPort == -1)
                {
                    return 1;
                }

                if (!hostname.HasValue())
                {
                    logger.LogError($"Option \"{hostname.LongName}\" is missing.");
                    return 1;
                }

                var program = new Program(intPort, hostname.Value(), loggerFactory);
                program.OpenChannel();

                return 0;
            });

            return app.Execute(args);
        }
Exemple #7
0
        public void ConfigureServices(IServiceCollection services)
        {
            var loggerFactory = new LoggerFactory { MinimumLevel = LogLevel.Debug };
            loggerFactory.AddConsole();
            loggerFactory.AddDebug();

            services.AddMvc(
                config =>
                    {
                        config.Filters.Add(new GlobalFilter(loggerFactory));
                        config.Filters.Add(new GlobalLoggingExceptionFilter(loggerFactory));
                    });

            services.AddScoped<ConsoleLogActionOneFilter>();
            services.AddScoped<ConsoleLogActionTwoFilter>();
            services.AddScoped<ClassConsoleLogActionBaseFilter>();
            services.AddScoped<ClassConsoleLogActionOneFilter>();

            services.AddScoped<CustomOneLoggingExceptionFilter>();
            services.AddScoped<CustomTwoLoggingExceptionFilter>();
            services.AddScoped<CustomOneResourceFilter>();   
        }
 public TestTracingInterceptor()
 {
     var factory = new LoggerFactory();
     _logger = factory.CreateLogger<TestTracingInterceptor>();
     factory.AddConsole();
 }
 static ServiceController()
 {
     var factory = new LoggerFactory();
     _logger = factory.CreateLogger<ServiceController>();
     factory.AddConsole();
 }
Exemple #10
0
 public Program()
 {
     var loggerFactory = new LoggerFactory();
     loggerFactory.AddConsole();
     _logger = loggerFactory.CreateLogger<Program>();
 }
Exemple #11
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            // Add framework services.
            var sqlLoggerFactory = new LoggerFactory();
            sqlLoggerFactory.AddConsole(Configuration.GetSection("SqlLogging"));

            var entityFramework = services;
            if (WebAppConfiguration.TDataBaseServerType == Message.TDataBaseServerType.PostgreSQL)
            {
                entityFramework = entityFramework.AddEntityFrameworkNpgsql().AddDbContext<ApplicationDbContext>(options =>
                    options.UseNpgsql(WebAppConfiguration.DatabaseConnectionString).UseLoggerFactory(sqlLoggerFactory));
            }
            else if (WebAppConfiguration.TDataBaseServerType == Message.TDataBaseServerType.SqlServer)
            {
                entityFramework = entityFramework.AddEntityFrameworkSqlServer().AddDbContext<ApplicationDbContext>(options =>
                    options.UseSqlServer(WebAppConfiguration.DatabaseConnectionString).UseLoggerFactory(sqlLoggerFactory));
            }
            else
                _logger.LogError("Unknown database connection type");

            services.AddIdentity<ApplicationUser, IdentityRole>(
                o => {
                    o.Password.RequireDigit = false;
                    o.Password.RequireLowercase = false;
                    o.Password.RequireUppercase = false;
                    o.Password.RequireNonAlphanumeric = false;
                    o.Password.RequiredLength = 6;
                }).AddEntityFrameworkStores<ApplicationDbContext>()
                .AddDefaultTokenProviders();

            //Link my own Localizer
            services.AddSingleton<IStringLocalizerFactory, StringLocalizerFactory>();

            services.AddLocalization(options => options.ResourcesPath = "Resources");

            services.Configure<IdentityOptions>(options =>
            {
                options.Cookies.ApplicationCookie.ExpireTimeSpan = TimeSpan.FromDays(10);
                options.Cookies.ApplicationCookie.LoginPath = new Microsoft.AspNetCore.Http.PathString("/Site/Account/Login");
                options.Cookies.ApplicationCookie.Events = new CookieAuthenticationEvents
                {
                    OnRedirectToAccessDenied = ctx => {
                        if (ctx.Request.Path.StartsWithSegments("/api"))
                        {
                            ctx.Response.StatusCode = 403;
                        }
                        else
                        {
                            ctx.Response.Redirect(ctx.RedirectUri);
                        }
                        return Task.FromResult(0);
                    },
                    OnRedirectToLogin = ctx => {
                        if (ctx.Request.Path.StartsWithSegments("/api") && ctx.Response.StatusCode == 200)
                        {
                            ctx.Response.StatusCode = 401;
                        }
                        else
                        {
                            ctx.Response.Redirect(ctx.RedirectUri);
                        }
                        return Task.FromResult(0);
                    },
                };
            });

            /*
            services.Configure<CookieAuthenticationOptions>(opt =>
            {
                opt.AccessDeniedPath = "/Site/Home/Index";
                opt.LogoutPath = "/Site/Account/Login";
                opt.LoginPath = "/Site/Account/Login";
            });
            */

            services.AddMvc().AddViewLocalization(options => options.ResourcesPath = "Resources").AddDataAnnotationsLocalization();

            services.AddAuthorization(options =>
            {
                options.AddPolicy("AllowLocalhost",
                                  policy => policy.Requirements.Add(new LoopBackAuthorizeRequirement()));
            });
            services.AddSingleton<IAuthorizationHandler, LoopBackAuthorizeHandler>();

            //Add service for manage cache data
            services.AddMemoryCache();

            // Add application services.
            services.AddTransient<IEmailSender, AuthMessageSender>();
            services.AddTransient<ISmsSender, AuthMessageSender>();

            ConfigureServiceDataLayer(services);

            services.Configure<RequestLocalizationOptions>(options =>
            {
                DefineLocalization(options);
            });

            WebAppConfiguration.ServiceProvider = services.BuildServiceProvider();
        }
Exemple #12
0
        static void Main(string[] args)
        {
            ILoggerFactory logfactory = new Microsoft.Extensions.Logging.LoggerFactory();
            Random         r          = new Random((int)(DateTime.Now.Ticks + (long)Environment.CurrentManagedThreadId));

            IConfigurationRoot config = new ConfigurationBuilder()
                                        .AddJsonFile("appsettings.json", optional: false)
                                        .Build();
            var cfg = config.Get <MqttConfig>();

            logfactory.AddConsole(true);


            switch (cfg.mode)
            {
            case (1):
            case (2):
            { break; }

            default:
            {
                Console.WriteLine("Mode (1=listen,2=publish)");
                string m = Console.ReadLine();
                cfg.mode = int.Parse(m);
                break;
            }
            }
            ;

            switch (cfg.mode)
            {
            case (2):
            {
                Console.WriteLine("publishing!");
                var t = _publish().Result;
                break;
            }

            case (1):
            {
                Console.WriteLine("subscribing!");
                var xm = new XamMqtt(cfg, logfactory.CreateLogger <XamMqtt>());
                xm.subscribe();
                //_subscribe(cfg);
                break;
            }
            }

            /*
             *   if (mode == 1)
             *     {
             *       client.MessageStream.Subscribe(new Obs());
             *       var t = client.SubscribeAsync("house/serverroom/temp", System.Net.Mqtt.MqttQualityOfService.AtLeastOnce);
             *       t.Wait();
             *     }
             *
             *   Console.WriteLine("Type 'q' to quit");
             *   string text = null;
             *   do {
             *     text = Console.ReadLine();
             *     if (mode == 2 && text != "q")
             *       {
             *         if (!client.IsConnected)
             *           {
             *             client.ConnectAsync(new MqttClientCredentials("blarg")).Wait();
             *           }
             *         var x = _SendMsg(r, client).Result;
             *         Console.WriteLine(x);
             *       }
             *
             *   } while(text != "q");
             *
             *   var t1 = client.DisconnectAsync();
             *   t1.Wait();
             *   client.Dispose();
             */
        }
Exemple #13
0
 static Log()
 {
     var factory = new LoggerFactory();
     factory.AddConsole(minLevel: LogLevel.Information);
     logger = factory.CreateLogger("diagnostics");
 }
Exemple #14
-1
        public TestHelper()
        {
            LoggerFactory = new LoggerFactory();

            var testVerbose = Environment.GetEnvironmentVariable("DOTNET_TEST_VERBOSE");
            if (testVerbose == "2")
            {
                LoggerFactory.AddConsole(LogLevel.Trace);
            }
            else if (testVerbose == "1")
            {
                LoggerFactory.AddConsole(LogLevel.Information);
            }
            else
            {
                LoggerFactory.AddConsole(LogLevel.Warning);
            }

            _tempPath = CreateTempFolder();
            var dthTestProjectsFolder = Path.Combine(FindRoot(), "testapp", "DthTestProjects");
            CopyFiles(dthTestProjectsFolder, _tempPath);

            var logger = LoggerFactory.CreateLogger<TestHelper>();
            logger.LogInformation($"Test projects are copied to {_tempPath}");
        }
        public void AspNetCoreLogging_MinLogLevel_Debug()
        {
            var external = new LoggerFactory();

            // TODO: remove in RC2
            external.MinimumLevel = LogLevel.Debug;
            // TODO: change Debug to Trace in RC2 (yes, in RC1 Verbose is higher than debug, and Verbose got renamed to Trace, later, too!)
            external.AddConsole(LogLevel.Verbose);

            var loggerFactory = new MicrosoftLoggerFactoryAdapter(external);
            var logger = loggerFactory.CreateLogger("cat");

            logger.Should().NotBeNull();
            logger.IsEnabled(Core.Logging.LogLevel.Trace).Should().BeFalse();
            logger.IsEnabled(Core.Logging.LogLevel.Debug).Should().BeTrue();
            logger.IsEnabled(Core.Logging.LogLevel.Information).Should().BeTrue();
            logger.IsEnabled(Core.Logging.LogLevel.Warning).Should().BeTrue();
            logger.IsEnabled(Core.Logging.LogLevel.Error).Should().BeTrue();
            logger.IsEnabled(Core.Logging.LogLevel.Critical).Should().BeTrue();
        }
Exemple #16
-1
        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());
        }