当前位置: 首页>>代码示例>>C#>>正文


C# ServiceCollection.AddLogging方法代码示例

本文整理汇总了C#中ServiceCollection.AddLogging方法的典型用法代码示例。如果您正苦于以下问题:C# ServiceCollection.AddLogging方法的具体用法?C# ServiceCollection.AddLogging怎么用?C# ServiceCollection.AddLogging使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ServiceCollection的用法示例。


在下文中一共展示了ServiceCollection.AddLogging方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

        public async Task Main()
        {
            var services = new ServiceCollection();
            services.AddDefaultServices(defaultProvider);
            services.AddAssembly(typeof(Program).GetTypeInfo().Assembly);
            services.AddOptions();
            services.AddSingleton(x => MemoryCache.INSTANCE);
            services.AddLogging();
            services.AddGlobalConfiguration(environment);

            var provider = services.BuildServiceProvider();

            var logging = provider.GetService<ILoggerFactory>();
            logging.AddProvider(provider.GetService<ISNSLoggerProvider>());
            logging.AddConsole();

            var cancellationSource = new CancellationTokenSource();

            var taskRunner = new TaskRunner(logging.CreateLogger<TaskRunner>(), provider);

            var tasks = taskRunner.RunTasksFromAssembly(typeof(Program).GetTypeInfo().Assembly, cancellationSource.Token);

            Console.CancelKeyPress += (sender, e) =>
            {
                Console.WriteLine("Caught cancel, exiting...");
                cancellationSource.Cancel();
            };

            await Task.WhenAll(tasks);
        }
开发者ID:alanedwardes,项目名称:aeblog,代码行数:30,代码来源:Program.cs

示例2: ManageControllerTest

        public ManageControllerTest()
        {
            var efServiceProvider = new ServiceCollection().AddEntityFrameworkInMemoryDatabase().BuildServiceProvider();

            var services = new ServiceCollection();
            services.AddOptions();
            services
                .AddDbContext<MusicStoreContext>(b => b.UseInMemoryDatabase().UseInternalServiceProvider(efServiceProvider));

            services.AddIdentity<ApplicationUser, IdentityRole>()
                    .AddEntityFrameworkStores<MusicStoreContext>();

            services.AddLogging();
            services.AddOptions();

            // IHttpContextAccessor is required for SignInManager, and UserManager
            var context = new DefaultHttpContext();
            context.Features.Set<IHttpAuthenticationFeature>(new HttpAuthenticationFeature() { Handler = new TestAuthHandler() });
            services.AddSingleton<IHttpContextAccessor>(
                new HttpContextAccessor()
                    {
                        HttpContext = context,
                    });

            _serviceProvider = services.BuildServiceProvider();
        }
开发者ID:Cream2015,项目名称:MusicStore,代码行数:26,代码来源:ManageControllerTest.cs

示例3: ConfigureServices

 private IServiceProvider ConfigureServices()
 {
     var services = new ServiceCollection();
     DbUtil.ConfigureDbServices<IdentityDbContext>(ConnectionString, services);
     services.AddLogging();
     services.AddIdentity<IdentityUser, IdentityRole>().AddEntityFrameworkStores<IdentityDbContext>();
     return services.BuildServiceProvider();
 }
开发者ID:adwardliu,项目名称:Identity,代码行数:8,代码来源:DefaultPocoTest.cs

示例4: CreateTestServices

 public static IServiceCollection CreateTestServices()
 {
     var services = new ServiceCollection();
     services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
     services.AddLogging();
     services.AddIdentity<IdentityUser, IdentityRole>();
     return services;
 }
开发者ID:yonglehou,项目名称:Identity-1,代码行数:8,代码来源:TestIdentityFactory.cs

示例5: Main

        public static void Main(string[] args)
        {
            #if !NET451
            Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
            #endif
            var serviceCollection = new ServiceCollection();

            serviceCollection
                .AddLogging()
                .AddClient()
            #if !NET451
                .UseSharedFileRouteManager(System.IO.Path.Combine(AppContext.BaseDirectory,"routes.txt"))
            #else
                .UseSharedFileRouteManager("d:\\routes.txt")
            #endif
                .UseSimpleTransport()
                .UseProtoBufferCodec();

            var serviceProvider = serviceCollection.BuildServiceProvider();

            serviceProvider.GetRequiredService<ILoggerFactory>()
                .AddConsole((c, l) => (int)l >= 3);

            var serviceProxyGenerater = serviceProvider.GetRequiredService<IServiceProxyGenerater>();
            var serviceProxyFactory = serviceProvider.GetRequiredService<IServiceProxyFactory>();
            var services = serviceProxyGenerater.GenerateProxys(new[] { typeof(IUserService) }).ToArray();

            //创建IUserService的代理。
            var userService = serviceProxyFactory.CreateProxy<IUserService>(services.Single(typeof(IUserService).GetTypeInfo().IsAssignableFrom));

            var logger = serviceProvider.GetRequiredService<ILogger<Program>>();
            while (true)
            {
                Task.Run(async () =>
                {
                    try
                    {
                        Console.WriteLine($"userService.GetUserName:{await userService.GetUserName(1)}");
                        Console.WriteLine($"userService.GetUserId:{await userService.GetUserId("rabbit")}");
                        Console.WriteLine($"userService.GetUserLastSignInTime:{await userService.GetUserLastSignInTime(1)}");
                        Console.WriteLine($"userService.Exists:{await userService.Exists(1)}");
                        var user = await userService.GetUser(1);
                        Console.WriteLine($"userService.GetUser:name={user.Name},age={user.Age}");
                        Console.WriteLine($"userService.Update:{await userService.Update(1, user)}");
                        Console.WriteLine($"userService.GetDictionary:{(await userService.GetDictionary())["key"]}");
                        await userService.TryThrowException();
                    }
                    catch (RpcRemoteException remoteException)
                    {
                        logger.LogError(remoteException.Message);
                    }
                }).Wait();
                Console.ReadLine();
            }
        }
开发者ID:yonglehou,项目名称:Rpc-1,代码行数:55,代码来源:Program.cs

示例6: ZooKeeperServiceRouteManagerTests

        public ZooKeeperServiceRouteManagerTests()
        {
            var services = new ServiceCollection();
            services
                .AddLogging()
                .AddRpcCore()
                .UseZooKeeperRouteManager(new ZooKeeperServiceRouteManager.ZookeeperConfigInfo("172.18.20.132:2181",
                    "/dotnet/unitTest/serviceRoutes"));
            var provider = services.BuildServiceProvider();

            ServiceRouteManager = (ZooKeeperServiceRouteManager)provider.GetRequiredService<IServiceRouteManager>();
        }
开发者ID:yaozd,项目名称:Rpc,代码行数:12,代码来源:ZooKeeperServiceRouteManagerTests.cs

示例7: SharedFileServiceRouteManagerTests

        public SharedFileServiceRouteManagerTests()
        {
            var routeFile = Path.Combine(AppContext.BaseDirectory, "routes.txt");
            var services = new ServiceCollection();
            services
                .AddLogging()
                .AddRpcCore()
                .UseSharedFileRouteManager(routeFile);
            var provider = services.BuildServiceProvider();

            ServiceRouteManager = (SharedFileServiceRouteManager)provider.GetRequiredService<IServiceRouteManager>();
        }
开发者ID:yaozd,项目名称:Rpc,代码行数:12,代码来源:SharedFileServiceRouteManagerTests.cs

示例8: HomeControllerTests

        public HomeControllerTests()
        {
            var services = new ServiceCollection();

            services.AddLogging();
            services.AddTransient<IRepository<AppTenant>, InMemoryRepository<AppTenant, string>>();
            services.AddTransient<IRepository<WishDay>, InMemoryRepository<WishDay, int>>();
            services.AddTransient<IRepository<WishItem>, InMemoryRepository<WishItem, int>>();
            services.AddTransient<IRepository<WishItemTag>, InMemoryRepository<WishItemTag, int>>();
            services.AddTransient<IUnitOfWorkContext, MyWishesUnitOfWorkDbContext>();
            services.AddTransient<IUnitOfWorkContext, MyWishesUnitOfWorkInMemoryContext>();
            services.AddTransient<ITenantsService, TenantsService>();
            
            _serviceProvider = services.BuildServiceProvider();
        }
开发者ID:SergiyTrygub,项目名称:mynotes,代码行数:15,代码来源:HomeControllerTests.cs

示例9: Main

        public static void Main(string[] args)
        {
            Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);

            var serviceCollection = new ServiceCollection();

            serviceCollection
                .AddLogging()
                .AddRpcCore()
                .AddServiceRuntime()
                .UseSharedFileRouteManager("d:\\routes.txt")
                .UseSimpleTransport();
            serviceCollection.AddTransient<IUserService, UserService>();

            var serviceProvider = serviceCollection.BuildServiceProvider();

            serviceProvider.GetRequiredService<ILoggerFactory>()
                .AddConsole((c, l) => (int)l >= 3);

            //自动生成服务路由(这边的文件与Echo.Client为强制约束)
            {
                var serviceEntryManager = serviceProvider.GetRequiredService<IServiceEntryManager>();
                var addressDescriptors = serviceEntryManager.GetEntries().Select(i => new ServiceRoute
                {
                    Address = new[]
                    {
                        new IpAddressModel { Ip = "127.0.0.1", Port = 9981 }
                    },
                    ServiceDescriptor = i.Descriptor
                });

                var serviceRouteManager = serviceProvider.GetRequiredService<IServiceRouteManager>();
                serviceRouteManager.SetRoutesAsync(addressDescriptors).Wait();
            }

            var serviceHost = serviceProvider.GetRequiredService<IServiceHost>();

            Task.Factory.StartNew(async () =>
            {
                //启动主机
                await serviceHost.StartAsync(new IPEndPoint(IPAddress.Parse("127.0.0.1"), 9981));
                Console.WriteLine($"服务端启动成功,{DateTime.Now}。");
            });
            Console.ReadLine();
        }
开发者ID:RabbitTeam,项目名称:Rpc,代码行数:45,代码来源:Program.cs

示例10: Main

        public static void Main(string[] args)
        {
            var serviceCollection = new ServiceCollection();

            serviceCollection
                .AddLogging()
                .AddRpcCore()
                //                .UseJsonCodec()
                .UseProtoBufferCodec()
                .AddServiceRuntime()
                .UseSharedFileRouteManager("d:\\routes.txt")
                //zookeeper服务路由管理者。
                //                .UseZooKeeperRouteManager(new ZooKeeperServiceRouteManager.ZookeeperConfigInfo("172.18.20.132:2181"))
                .UseDotNettyTransport();

            var serviceProvider = serviceCollection.BuildServiceProvider();

            serviceProvider.GetRequiredService<ILoggerFactory>()
                .AddConsole((c, l) => (int)l >= 3);

            //自动生成服务路由(这边的文件与Echo.Client为强制约束)
            {
                var serviceEntryManager = serviceProvider.GetRequiredService<IServiceEntryManager>();
                var addressDescriptors = serviceEntryManager.GetEntries().Select(i => new ServiceRoute
                {
                    Address = new[] { new IpAddressModel { Ip = "127.0.0.1", Port = 9981 } },
                    ServiceDescriptor = i.Descriptor
                });

                var serviceRouteManager = serviceProvider.GetRequiredService<IServiceRouteManager>();
                serviceRouteManager.AddRoutesAsync(addressDescriptors).Wait();
            }

            var serviceHost = serviceProvider.GetRequiredService<IServiceHost>();

            Task.Factory.StartNew(async () =>
            {
                //启动主机
                await serviceHost.StartAsync(new IPEndPoint(IPAddress.Parse("127.0.0.1"), 9981));
                Console.WriteLine($"服务端启动成功,{DateTime.Now}。");
            });
            Console.ReadLine();
        }
开发者ID:cjt908,项目名称:Rpc,代码行数:43,代码来源:Program.cs

示例11: SqliteDatabaseModelFactoryTest

        public SqliteDatabaseModelFactoryTest()
        {
            _testStore = SqliteTestStore.CreateScratch();
            var serviceCollection = new ServiceCollection();
            serviceCollection.AddLogging()
                .AddSingleton<ModelUtilities>()
                .AddSingleton<CSharpUtilities>();
            new SqliteDesignTimeServices().ConfigureDesignTimeServices(serviceCollection);
            serviceCollection.AddSingleton<IFileService, FileSystemFileService>();

            var serviceProvider = serviceCollection
                .BuildServiceProvider();

            _logger = new TestLogger();
            serviceProvider.GetService<ILoggerFactory>().AddProvider(new TestLoggerProvider(_logger));

            _scaffoldingModelFactory = serviceProvider
                .GetService<IScaffoldingModelFactory>() as RelationalScaffoldingModelFactory;
        }
开发者ID:adwardliu,项目名称:EntityFramework,代码行数:19,代码来源:SqliteDatabaseModelFactoryTest.cs

示例12: CreateNode

        public static Node CreateNode(out IServiceProvider provider)
        {
            IServiceCollection sc = new ServiceCollection();
            sc.AddLogging();
            sc.AddInMemoryRPC();
            sc.AddRaft(p => {
                p.UseLogging = true;
                p.FailureTolerance = -1;
            });
            sc.AddMvc();
            sc.Configure<RaftOptions>(p => { });
            provider = sc.BuildServiceProvider();

            var loggerFactory = provider.GetService<ILoggerFactory>();
            loggerFactory.MinimumLevel = LogLevel.Information;
            loggerFactory.AddConsole();
            loggerFactory.AddDebug();
            
            return provider.GetService<Node>();
        }
开发者ID:RossMerr,项目名称:Caudex.Rafting,代码行数:20,代码来源:NodeBuilder.cs

示例13: WishDaysControllerTests

        public WishDaysControllerTests()
        {
            var efServiceProvider = new ServiceCollection().AddEntityFrameworkInMemoryDatabase().BuildServiceProvider();

            var services = new ServiceCollection();

            services.AddDbContext<MyWishesDbContext>(b => b.UseInMemoryDatabase().UseInternalServiceProvider(efServiceProvider));

            services.AddLogging();
            services.AddTransient<IRepository<AppTenant>, DbRepository<AppTenant, string>>();
            services.AddTransient<IRepository<WishDay>, DbRepository<WishDay, int>>();
            services.AddTransient<IRepository<WishItem>, DbRepository<WishItem, int>>();
            services.AddTransient<IRepository<WishItemTag>, DbRepository<WishItemTag, int>>();
            services.AddTransient<IUnitOfWorkContext, MyWishesUnitOfWorkDbContext>();

            services.AddTransient<IUnitOfWorkContext, MyWishesUnitOfWorkDbContext>();
            services.AddTransient<IWishDaysService, WishDaysService>();

            _serviceProvider = services.BuildServiceProvider();
        }
开发者ID:SergiyTrygub,项目名称:mynotes,代码行数:20,代码来源:WishDaysControllerTests.cs

示例14: VerifyAccountControllerSignIn

        public async Task VerifyAccountControllerSignIn(bool isPersistent)
        {
            var context = new Mock<HttpContext>();
            var auth = new Mock<AuthenticationManager>();
            context.Setup(c => c.Authentication).Returns(auth.Object).Verifiable();
            auth.Setup(a => a.SignInAsync(new IdentityCookieOptions().ApplicationCookieAuthenticationScheme,
                It.IsAny<ClaimsPrincipal>(),
                It.IsAny<AuthenticationProperties>())).Returns(Task.FromResult(0)).Verifiable();
            // REVIEW: is persistant mocking broken
            //It.Is<AuthenticationProperties>(v => v.IsPersistent == isPersistent))).Returns(Task.FromResult(0)).Verifiable();
            var contextAccessor = new Mock<IHttpContextAccessor>();
            contextAccessor.Setup(a => a.HttpContext).Returns(context.Object);
            var services = new ServiceCollection();
            services.AddLogging();
            services.AddSingleton(contextAccessor.Object);
            services.AddIdentity<TestUser, TestRole>();
            services.AddSingleton<IUserStore<TestUser>, InMemoryStore<TestUser, TestRole>>();
            services.AddSingleton<IRoleStore<TestRole>, InMemoryStore<TestUser, TestRole>>();
            
            var app = new ApplicationBuilder(services.BuildServiceProvider());
            app.UseCookieAuthentication();

            // Act
            var user = new TestUser
            {
                UserName = "Yolo"
            };
            const string password = "[email protected]!";
            var userManager = app.ApplicationServices.GetRequiredService<UserManager<TestUser>>();
            var signInManager = app.ApplicationServices.GetRequiredService<SignInManager<TestUser>>();

            IdentityResultAssert.IsSuccess(await userManager.CreateAsync(user, password));

            var result = await signInManager.PasswordSignInAsync(user, password, isPersistent, false);

            // Assert
            Assert.True(result.Succeeded);
            context.VerifyAll();
            auth.VerifyAll();
            contextAccessor.VerifyAll();
        }
开发者ID:xuchrist,项目名称:Identity,代码行数:41,代码来源:ControllerTest.cs

示例15: ShapeHelperTests

        public ShapeHelperTests()
        {
            IServiceCollection serviceCollection = new ServiceCollection();

            serviceCollection.AddLogging();
            serviceCollection.AddScoped<IHttpContextAccessor, StubHttpContextAccessor>();
            serviceCollection.AddScoped<IHtmlDisplay, DefaultIHtmlDisplay>();
            serviceCollection.AddScoped<IExtensionManager, StubExtensionManager>();
            serviceCollection.AddScoped<IThemeManager, ThemeManager>();
            serviceCollection.AddScoped<IShapeFactory, DefaultShapeFactory>();
            serviceCollection.AddScoped<IShapeTableManager, TestShapeTableManager>();


            var defaultShapeTable = new ShapeTable
            {
                Descriptors = new Dictionary<string, ShapeDescriptor>(StringComparer.OrdinalIgnoreCase),
                Bindings = new Dictionary<string, ShapeBinding>(StringComparer.OrdinalIgnoreCase)
            };
            serviceCollection.AddSingleton(defaultShapeTable);

            _serviceProvider = serviceCollection.BuildServiceProvider();
        }
开发者ID:jchenga,项目名称:Orchard2,代码行数:22,代码来源:ShapeHelperTests.cs


注:本文中的ServiceCollection.AddLogging方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。