我们是五月的花海 , 用青春拥抱|

兴想事成

园龄:12年10个月粉丝:25关注:97

开源日志组件Sejil--附带日志管理界面

1.开源日志组件源码:  https://github.com/alaatm/Sejil

2.下载下来发现里面对于不同的.net core 版本的配置提供了对应的示例

 

.Net Core 3.1

Program.cs文件中

    public class Program
    {
        public static void Main(string[] args) => CreateHostBuilder(args).Build().Run();

        public static IHostBuilder CreateHostBuilder(string[] args) =>
            Host.CreateDefaultBuilder(args)
                .UseSejil()
                .ConfigureWebHostDefaults(webBuilder => webBuilder.UseStartup<Startup>());
    }

 

Startup.cs

using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Sejil;

 public class Startup
    {
        public IConfiguration Configuration { get; }

        public Startup(IConfiguration configuration) => Configuration = configuration;

        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllersWithViews();
            services.ConfigureSejil(cfg => cfg.Title = "Logs");
        }

        // 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();
            }
            else
            {
                app.UseExceptionHandler("/Home/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.UseSejil();

            app.UseRouting();

            app.UseEndpoints(endpoints =>
                endpoints.MapControllerRoute(
                    name: "default",
                    pattern: "{controller=Home}/{action=Index}/{id?}"));
        }
    }

 

如果需要权限校验之类的

Program.cs文件中

   public class Program
    {
        public static void Main(string[] args)
        {
            AppContext.SetSwitch("System.Net.Http.UseSocketsHttpHandler", false);
            CreateHostBuilder(args).Build().Run();
        }

        public static IHostBuilder CreateHostBuilder(string[] args) =>
            Host.CreateDefaultBuilder(args)
                .UseSejil()
                .ConfigureWebHostDefaults(webBuilder => webBuilder.UseStartup<Startup>());
    }

 

Startup.cs 文件中

using Bazinga.AspNetCore.Authentication.Basic;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Sejil;

   public class Startup
    {
        public IConfiguration Configuration { get; }

        public Startup(IConfiguration configuration) => Configuration = configuration;

        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllersWithViews();

            services.AddAuthentication(BasicAuthenticationDefaults.AuthenticationScheme)
                .AddBasicAuthentication(credentials =>
                    Task.FromResult(credentials.username == "myUsername" && credentials.password == "myPassword")
                );

            services.ConfigureSejil(cfg => cfg.AuthenticationScheme = BasicAuthenticationDefaults.AuthenticationScheme);
        }

        // 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();
            }
            else
            {
                app.UseExceptionHandler("/Home/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.UseRouting();

            app.UseAuthentication();
            app.UseAuthorization();
            app.UseSejil();

            app.UseEndpoints(endpoints =>
                endpoints.MapControllerRoute(
                    name: "default",
                    pattern: "{controller=Home}/{action=Index}/{id?}"));
        }
    }

 

对应的 appsettings.json 配置文件

  "Authentication": {
        "Authority": "https://sample.auth0.com",
        "ResponseType": "code",
        "ClientId": "USER_SECRET",
        "ClientSecret": "USER_SECRET",
        "Scope": [
            "openid",
            "profile",
            "email"
        ],
        "CallbackPath": "/signin-auth0",
        "ClaimsIssuer": "Auth0"
    }

 

 

.Net Core 6

using Sejil;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddRazorPages();

// Configure Sejil
builder.Host.UseSejil(
    minLogLevel: LogLevel.Information,
    writeToProviders: true);

builder.Services.ConfigureSejil(cfg => cfg.Title = "My App Logs");
//////////////////

var app = builder.Build();

if (!app.Environment.IsDevelopment())
{
    app.UseExceptionHandler("/Error");
    app.UseHsts();
}

app.UseHttpsRedirection();
app.UseStaticFiles();

app.UseRouting();

app.UseAuthorization();

app.MapRazorPages();

// Add sejil to request pipeline
app.UseSejil();
//////////////////

app.Run();

 

 

另外补充一下: 源代码里面是 在本地  C:\Users\{电脑名}\AppData\Local\ 项目 下新建了 一个sqlite 文件

如果是项目发布,是在运行程序目录下 新建一个 业务文件夹\sqlite文件

 

访问 http://localhost:xxxx/Sejil   就可以看到对应的日志了.

 

posted @   兴想事成  阅读(270)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示
评论
收藏
关注
推荐
深色
回顶
收起
  1. 1 Good-bye My Loneliness ZARD
  2. 2 Say OK Vanessa Hudgens
  3. 3 All The Love In The World The Corrs
  4. 4 Adesso E Fortuna ~炎と永遠~ 加藤いづみ
Say OK - Vanessa Hudgens
00:00 / 00:00
An audio error has occurred, player will skip forward in 2 seconds.

作词 : BIRGISSON, ARNTHOR/KOTECHA, SAVAN

作曲 : Savan Kotecha/Arnthor Birgisson

Vanessa Hudgens - Say OK

Album: V

You are fine

You are fine

You are fine

You are fine

You are sweet

But I'm still a bit naive with my heart

When you're close I don't breathe

I can't find the words to speak

I feel sparks

But I don't wanna be into you

If you are not looking for true love, oh oh

No I don't wanna start seeing you

If I can't be your only one

So tell me when it's not alright

When it's not ok

Will you try to make me feel better?

Will you say alright? (say alright)

Will you say ok? (Say ok)

Will you stick with me through whatever?

Or run away

(Say that it's gonna be alright)

(That it's gonna be ok)

Say OK

When you call I don't know

If I should pick up the phone every time

I'm not like all my friends

Who keep calling up the boys, I'm so shy

But I don't wanna be into you

If you don't treat me the right way

See I can only start seeing you

If you can make my heart feel safe (feel safe)

When it's not alright

When it's not ok

Will you try to make me feel better?

Will you say alright? (say alright)

Will you say ok? (Say ok)

Will you stick with me through whatever?

Or run away

(Say that it's gonna be alright)

(That it's gonna be ok)

(Don't run away, don't run away)

Let me know if it's gonna be you

Boy, you've got some things to prove

Let me know that you'll keep me safe

I don't want you to run away so

Let me know that you'll call on time

Let me know that you won't be shy

Will you wipe my tears away

Will you hold me closer

When it's not alright

When it's not ok

Will you try to make me feel better

Will you say alright? (say alright)

Will you say ok? (Say ok)

Will you stick with me through whatever?

Or run away

(Say that it's gonna be alright)

(That it's gonna be ok)

Say OK

(Don't run away, don't run away)

(Say that it's gonna be alright)

(That it's gonna be ok)

(Don't run away)

Will you say OK

(Say that it's gonna be alright)

(That it's gonna be ok)

(Don't run away)

You are fine

You are fine