Exemplo n.º 1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            services.Configure <CookiePolicyOptions>(options =>
            {
                // This lambda determines whether user consent for non-essential cookies is needed for a given request.
                options.CheckConsentNeeded    = context => true;
                options.MinimumSameSitePolicy = SameSiteMode.None;
            });



            services.AddLogging(p => p.AddConsole());

            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);

            return(services.AddShawnService(option =>
            {
                //添加自己的服务
                option._IocManager.BuilderContainer.AddMyServices();


                var columnOptions = new ColumnOptions // 自定义字段
                {
                    AdditionalDataColumns = new Collection <DataColumn>
                    {
                        new DataColumn {
                            DataType = typeof(string), ColumnName = "User"
                        },
                        new DataColumn {
                            DataType = typeof(string), ColumnName = "TraceId"
                        }
                    }
                };
                //注入日志
                option.UseSerilog(p =>
                {
                    p.pathName = "C:\\Users\\RICH-IT-DEV\\Desktop\\Log.txt";
                    p.strTempName = "[{Timestamp:yyyy-MM-dd HH:mm:ss.fff}] {SourceContext} level: {Level:u4}, {Message:l}{NewLine}";
                    p.debugminEvent = Serilog.Events.LogEventLevel.Debug;
                    p.consoleminEvent = Serilog.Events.LogEventLevel.Verbose;
                    p.mssminEvent = Serilog.Events.LogEventLevel.Verbose;

                    p.msgTemp = "User: {User} TraceId:{TraceId}";
                    p.logTableName = "LogSerilog";
                    //默认false
                    p.NeedToConsole = true;
                    p.NeedToDebug = true;
                    p.NeedToMSS = true;
                    p.logConnectstr = Configuration["ConnectionStrings:Default"];
                });
            }));
        }
Exemplo n.º 2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            services.AddMvc(options =>
            {
                options.Filters.Add <RichExctption>();
            }).SetCompatibilityVersion(CompatibilityVersion.Version_2_2);

            services.AddSwaggerGen(options =>
            {
                options.DescribeAllEnumsAsStrings();
                options.SwaggerDoc("v1", new Swashbuckle.AspNetCore.Swagger.Info
                {
                    Title          = "Order Web Host Api",
                    Version        = "v1",
                    Description    = "Order for Rich",
                    TermsOfService = "Terms Of Order Apis"
                });
                // 为 Swagger JSON and UI设置xml文档注释路径
                var basePath = Path.GetDirectoryName(typeof(Program).Assembly.Location);//获取应用程序所在目录(绝对,不受工作目录影响,建议采用此方法获取路径)
                var xmlPath  = Path.Combine(basePath, "Rich.Order.Web.Host.xml");
                options.IncludeXmlComments(xmlPath);
            });
            services.AddCors(options =>
            {
                options.AddPolicy("CorsPolicy",
                                  builder => builder
                                  .WithOrigins(
                                      // CorsOrigins in appsettings.json can contain more than one address separated by comma.
                                      _appConfiguration["CorsOrigins"]
                                      .Split(",", StringSplitOptions.RemoveEmptyEntries)
                                      .ToArray()
                                      )
                                  .AllowAnyMethod()
                                  .AllowAnyHeader()
                                  .AllowCredentials());
            });

            services.AddConfigurationIdentity(_appConfiguration);
            services.AddRichAboutHttp();
            services.AddRichAutoMapper((service, map) =>
            {
                map.AddProfile(typeof(AccountProfile));
            }, new List <Type>()
            {
                typeof(AccountProfile)
            });

            return(services.AddShawnService(option =>
            {
                var iocManager = option._IocManager.BuilderContainer;
                iocManager.RegistAppServiceToContianer(_env);
                iocManager.RegistInfrastrctureToContianer(_env);
                var path = AppDomain.CurrentDomain.BaseDirectory;
                //注册

                var columnOptions = new ColumnOptions // 自定义字段
                {
                    AdditionalColumns = new Collection <SqlColumn>
                    {
                        new SqlColumn {
                            DataType = SqlDbType.VarChar, ColumnName = "User"
                        },
                        new SqlColumn {
                            DataType = SqlDbType.VarChar, ColumnName = "TraceId"
                        },
                        new SqlColumn {
                            DataType = SqlDbType.VarChar, ColumnName = "Msg"
                        },
                        new SqlColumn {
                            DataType = SqlDbType.DateTime, ColumnName = "CreateTime"
                        }
                    }
                };
                //注入日志
                option.UseSerilog(p =>
                {
                    //传空默认运行目录
                    p.pathName = string.Empty;
                    p.strTempName = "[{Timestamp:yyyy-MM-dd HH:mm:ss.fff}] {SourceContext} level: {Level:u4}, {Message:l}{NewLine}";
                    p.debugminEvent = LogEventLevel.Debug;
                    p.consoleminEvent = LogEventLevel.Verbose;
                    p.mssminEvent = LogEventLevel.Verbose;
                    p.columnOptions = columnOptions;
                    p.msgTemp = "User: {User} TraceId:{TraceId} Msg:{Msg} CreateTime:{CreateTime}";
                    p.logTableName = "RichLog";
                    //默认false
                    p.NeedToConsole = true;
                    p.NeedToDebug = true;
                    p.NeedToMSS = true;
                    p.logConnectstr = _appConfiguration["ConnectionStrings:Default"];
                });

                option.UseDapper(p => { p.DefaultConnectStrName = _appConfiguration["ConnectionStrings:Default"]; });
            }));
        }