2016-09-22 2 views
3

우수한 Serilog 라이브러리를 사용하여 asp.net 핵심 응용 프로그램에 로깅을 추가했습니다. Sql Server 및 Literate 콘솔에 대한 싱크를 추가했습니다.
SQL 서버 싱크는 완벽하게 작동하지만, 약간 당황 스럽지만 콘솔 창에 로그를 표시하는 방법이 없습니다.
이것은 필자가 뭘하려 : 나는 명령 DOTNET 실행을 실행하지만 project.json가 존재하지 않는 없다는 오류를 가지고있다IIS에서 호스팅하는 asp.net 핵심 응용 프로그램의 콘솔 로그는 어디에 있습니까

  1. 게시 된 디렉토리에서. 이 과정은 물론 파일이있는 내 컴퓨터에서 명령을 실행하면 작동합니다. 로그는 열리는 콘솔로 표시됩니다.
  2. 은 또한 직접 EXE을 실행하려고했습니다, 그리고 그것에서 수신 것을 말하고 있었다 : http://localhost:5000 있지만 기록은 콘솔 창에 표시되지 않았다.

    public Startup(IHostingEnvironment env) 
        { 
         var builder = new ConfigurationBuilder() 
          .SetBasePath(env.ContentRootPath) 
          .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) 
          .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true) 
          .AddEnvironmentVariables(); 
         Configuration = builder.Build(); 
    
         ConfigureLogging(); 
        } 
    
        private void ConfigureLogging() 
        { 
         Log.Logger = new LoggerConfiguration() 
          .MinimumLevel.Verbose() 
          .WriteTo.LiterateConsole(LogEventLevel.Verbose) 
          .WriteTo.RollingFile(".\\Logs\\log-{Date}.txt") 
          .WriteTo.MSSqlServer(Configuration.GetConnectionString("Logging"), "Logs"/*, columnOptions: new ColumnOptions()*/) 
          .CreateLogger(); 
        } 
    
        public IConfigurationRoot Configuration { get; } 
    
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IApplicationLifetime appLifetime) 
        { 
         app.Use(async (context, next) => 
         { 
          await next(); 
    
          // If there's no available file and the request doesn't contain an extension, we're probably trying to access a page. 
          // Rewrite request to use app root 
          if (context.Response.StatusCode == 404 && !Path.HasExtension(context.Request.Path.Value)) 
          { 
           context.Request.Path = "/"; // Put your Angular root page here 
           await next(); 
          } 
         }); 
    
         loggerFactory 
          .AddSerilog(); 
    
         // Ensure any buffered events are sent at shutdown 
         appLifetime.ApplicationStopped.Register(Log.CloseAndFlush); 
    
         if (env.IsDevelopment()) 
         { 
          app.UseDeveloperExceptionPage(); 
          app.UseBrowserLink(); 
         } 
         else 
         { 
          app.UseExceptionHandler("/Home/Error"); 
         } 
    
         app.UseDefaultFiles(); 
         app.UseStaticFiles(); 
    
         //app.UseCors(builder => builder.AllowAnyOrigin()); 
         app.UseMvc(); 
    
    
    
         //app.UseHangfireDashboard();    // Will be available under http://localhost:5000/hangfire 
         //app.UseHangfireServer(); 
        } 
    

    가 어떻게 콘솔 창에 로그를 표시 할 : 여기

코드인가?

+0

로그 구성 방법을 알려주십시오. –

+0

확실한 Fabricio 코드를 붙이겠다 – ashilon

답변

2

IIS에서는 콘솔 로그가 수집되지 않습니다. 구성한 롤링 파일과 같이 IIS에서 호스팅하는 응용 프로그램에 대해 다른 싱크 중 하나를 사용해야합니다.

+0

안녕하세요, 마스터 님 자신이 보낸 코멘트입니다 :-) Thanks a lot Nicholas – ashilon

관련 문제