C# 使用.NET core 3/3.1的Linux CentOS 8中未显示任何日志

C# 使用.NET core 3/3.1的Linux CentOS 8中未显示任何日志,c#,linux,.net-core,serilog,centos8,C#,Linux,.net Core,Serilog,Centos8,我很想给出错误信息,但这是我得到的全部 我错过什么了吗?在.NETCore3.1和2.1/2.2版本中,Linux部署做了额外的改变吗 我试着尽快注销 Program.cs public class Program { public static void Main(string[] args) { bool dev = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONM

我很想给出错误信息,但这是我得到的全部

我错过什么了吗?在.NETCore3.1和2.1/2.2版本中,Linux部署做了额外的改变吗

我试着尽快注销

Program.cs

public class Program
    {
        public static void Main(string[] args)
        {
            bool dev = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") == "Development";
            var logPath = dev ? "/Logs/gweb_log.txt" : "/var/log/gweb/gweb.log";

            Log.Logger = new LoggerConfiguration()
                .MinimumLevel.Debug()
                //.MinimumLevel.Override("Microsoft", LogEventLevel.Information)
                .Enrich.FromLogContext()
                //.WriteTo.AzureApp()
                .WriteTo.File(logPath, rollingInterval: RollingInterval.Day, fileSizeLimitBytes: 10485760, rollOnFileSizeLimit: true, retainedFileCountLimit: 3)
                .CreateLogger();

            try
            {
                Log.Information($"Garos_Web Started Utc: {DateTime.UtcNow}!");
                CreateHostBuilder(args).Build().Run();
            }

            catch (Exception e)
            {
                Log.Error($"Something went wrong. UTC: {DateTime.UtcNow}");
                Log.Error(e.Message);
                if (e.InnerException != null && !string.IsNullOrEmpty(e.InnerException.Message))
                {
                    Log.Error(e.InnerException.Message);
                }

                Log.Error(e.StackTrace);
            }
            finally
            {
                Log.CloseAndFlush();
            }

        }

        public static IHostBuilder CreateHostBuilder(string[] args) =>
            Host.CreateDefaultBuilder(args)
                .ConfigureWebHostDefaults(webBuilder =>
                {
                    webBuilder.UseSerilog()
                    .UseStartup<Startup>()
                    .UseKestrel(options =>
                    {
                        options.Listen(System.Net.IPAddress.Loopback, 5000);
                    });
                }
            );
    }

.WriteTo.Console()
添加到serilog设置中如何?您还需要在相关的csproj文件中包含此包:

您似乎正在将日志写入
/var/log/gweb/gweb.log
,但正在读取
/var/log/messages
?我已经尝试过了,但检查时没有日志输出到
/var/log/gweb/gweb.log
。所以我希望就是这样。谢谢你!最后,我可以像一个正常人一样调试,而无需拔出我的头发<代码>[13:44:22错误]出了问题。UTC:3/1/2020 12:44:22 PM[13:44:22 ERR]错误:2006D080:BIO例程:BIO_new_文件:Interop.Crypto.checkvalidOpensLX509CertificateReader.FromFile中的Interop.Crypto.checkvalidOpensLX509KeystrageFlags中没有这样的文件[13:44:22 ERR]。
public class Startup
    {
        public Startup(IConfiguration configuration, IWebHostEnvironment webHostEnvironment)
        {
            Configuration = configuration;
            WebHostEnvironment = webHostEnvironment;
        }

        public IConfiguration Configuration { get; }
        public IWebHostEnvironment WebHostEnvironment { get; }

        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            Configuration.GetSection("AppSettings").Bind(AppSettings.Default);

            services.AddDbContext<GarosWebDbContext>(options =>
                options.UseMySql(AppSettings.Default.ConnectionStrings.DefaultConnection));

            services.AddDefaultIdentity<GarosUser>(options => options.SignIn.RequireConfirmedAccount = true)
                .AddEntityFrameworkStores<GarosWebDbContext>();


            var certPath = Path.Combine(WebHostEnvironment.ContentRootPath, "garos_web_identity_server.pfx");
            var cert = new X509Certificate2(certPath, AppSettings.Default.IdentitySigningKey);

            services.AddIdentityServer()              
            .AddApiAuthorization<GarosUser, GarosWebDbContext>()
            .AddSigningCredential(cert);


            services.AddAuthentication()
                .AddIdentityServerJwt();

            services.AddControllersWithViews();

            services.AddRazorPages();

            // In production, the React files will be served from this directory
            services.AddSpaStaticFiles(configuration =>
            {
                configuration.RootPath = "ClientApp/build";
            });

        }

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseDatabaseErrorPage();
            }
            else
            {
                app.UseExceptionHandler("/Error");
                // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                app.UseHsts();
            }

            //app.UseHttpsRedirection();
            app.UseStaticFiles();
            app.UseSpaStaticFiles();

            app.UseRouting();

            app.UseAuthentication();
            app.UseIdentityServer();
            app.UseAuthorization();


#if !DEBUG //Stop Registering users when in production (this is because we are using identity out of the box and don't want to allow more users at this time)
            app.UseAuthorization().Use((async (context, next) => {


                if (context.Request.RouteValues.Values.Contains("/Account/Register"))
                {
                    Debug.WriteLine("Inside");
                    context.Response.StatusCode = 404;                              
                }

                else
                {
                    await next();
                }
            }));
#endif
            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllerRoute(
                    name: "default",
                    pattern: "{controller}/{action=Index}/{id?}");
                endpoints.MapRazorPages();                
            });

            app.UseSpa(spa =>
            {
                spa.Options.SourcePath = "ClientApp";

                if (env.IsDevelopment())
                {
                    spa.UseReactDevelopmentServer(npmScript: "start");
                }
            });
        }
    }

[Unit]
Description=GAROS_WEB .NET Web Application running on CentOS 8

[Service]
WorkingDirectory=/website_production/PublishOutput
ExecStart=/usr/share/dotnet/dotnet /website_production/PublishOutput/garos_web.dll
Restart=always
# restart service after 10 seconds if dotnet service crashes
RestartSec=10
SyslogIdentifier=garos_web_webapp
User=garos_web
Environment=ASPNETCORE_ENVIRONMENT=Production
Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false

[Install]
WantedBy=multi-user.target