首页 > 其他分享 >开源日志组件Sejil--附带日志管理界面

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

时间:2023-08-12 17:55:14浏览次数:57  
标签:-- app args Microsoft Sejil services using 日志 public

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   就可以看到对应的日志了.

 

标签:--,app,args,Microsoft,Sejil,services,using,日志,public
From: https://www.cnblogs.com/mjxxsc/p/17625168.html

相关文章

  • 本周进度报告-5
    (1)这周我继续学习大数据和练车;在大数据方面已经配置完成了hadoop的虚拟机环境和xshell以及xftp;另外所幸这周通过了科目二的考试,有惊无险的通过了,接下来就是科目三了;这周的天气也是时好时坏,经常下雨,但是却很热;前天的模拟考试和昨天的科目二考试都是一大早就出发,我只好三四点就起床,......
  • 科学家精神
    科学家精神的主要内涵包括六个方面:胸怀祖国、服务人民的爱国精神,勇攀高峰、敢为人先的创新精神,追求真理、严谨治学的求实精神,淡泊名利、潜心研究的奉献精神,集智攻关、团结协作的协同精神,甘为人梯、奖掖后学的育人精神。​​​......
  • 2023/08/12
    《咱俩谁管谁叫爹》是网上一首搞笑饶舌歌曲,来源于东北酒桌上的助兴游戏。现在我们把这个游戏的难度拔高一点,多耗一些智商。不妨设游戏中的两个人为A和B。游戏开始后,两人同时报出两个整数NA​和NB​。判断谁是爹的标准如下:将两个整数的各位数字分别相加,得到两......
  • 公钥 & 数字证书 & 分布式身份DID (上)
    主页个人微信公众号:密码应用技术实战个人博客园首页:https://www.cnblogs.com/informatics/引言密码技术中最令人兴奋的密码算法简介类别算法描述对称加密算法AES(AdvancedEncryptionStandard)使用不同密钥长度(128位、192位、256位),广泛用于数据保密。DE......
  • tikz
    ......
  • pyspark小案例
    ##py_pyspark_demo.py#py_learn##CreatedbyZ.Steveon2023/8/1215:33.##统计文件中各个单词出现的次数#1.导入库frompysparkimportSparkConf,SparkContext#2.创建SparkConf对象和SparkContext对象conf=SparkConf().setMaster("local......
  • 硬件管理平台-硬件网关-插件模块-集成(上)
    硬件管理平台-硬件网关-插件模块-集成(上)本章内容本章主要是将插件项目(HardwareGatewayPlugin)集成到HardwareGatewayWebApi项目中。操作创建单例模式类由于HardwareGatewayWebApi项目是WebApi项目,可能后续还会有其他controller加入进来,因此我们的插件模块只针对HardwareGatewa......
  • 编写一份接口需求文档
    一、什么是接口百科上对接口的定义:API(ApplicationProgrammingInterface,应用程序编程接口)是一些预先定义的函数,目的是提供应用程序与开发人员基于某软件或硬件得以访问一组例程的能力,而又无需访问源码,或理解内部工作机制的细节。理解一下为什么要用接口?两个独立的系统,它们的......
  • ICCV 2023 | 旷视研究院入选论文亮点解读
    前言 近日,国际计算机视觉大会ICCV(InternationalConferenceonComputerVision)公布了2023年论文录用结果,本届会议共有8068篇投稿,接收率为26.8%。ICCV是全球计算机领域顶级的学术会议,每两年召开一次,ICCV2023将于今年10月在法国巴黎举行。今年,旷视研究院14篇论文入选,涵......
  • 静态成员(static)VS extern
    static与extern区别静态成员(static)静态全局变量:限制作用域,只在定义该变量的源文件内有效作用于全局变量时:叫静态全局变量。表示该变量是私有的,只能在该文件使用。不能通过extern关键字对其引用。静态局部变量:改变局部变量的生存周期,使得该变量存在于定义直到程序......