第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

有沒有辦法關閉 Hangfire 對 serilog 所做的日志記錄?

有沒有辦法關閉 Hangfire 對 serilog 所做的日志記錄?

C#
人到中年有點甜 2022-01-09 16:54:29
有沒有辦法關閉 Hangfire 對 serilog 所做的日志記錄?我們正在使用我們自己的抽象,我不希望在使用 serilog 時來自 Hangfire 記錄器的所有這些額外噪音。// INIT call under web project namespace MYApp.Web.App_Start{    public static class Bootstrapper    {        public static void Run()        {            Core.Logging.Serilog.SetConfiguration();        }    }}// 設置配置方法的項目namespace MYApp.Core.Logging{ public static class Serilog    {      public static void SetConfiguration()            {                Log.Logger = new LoggerConfiguration()                    //.WriteTo.File(@"c:\log-.txt", rollingInterval: RollingInterval.Minute, shared: true)                    .WriteTo.Email(new EmailConnectionInfo()                    {                        FromEmail = "xxxxxx@gmail.com",                        MailServer = "smtp.gmail.com",                        ToEmail = "xxxx@xxxx.xx.xx",                        NetworkCredentials = new NetworkCredential("xxxx@gmail.com", "xxxxxxxxx"),                        Port = 587,                        EnableSsl = true,                        EmailSubject = "YYYYYY: Error Log"                    }, outputTemplate: "[{Timestamp:HH:mm:ss} {Level:u3}] {NewLine} {Message:lj}{NewLine}{Exception}")                    .Filter.ByExcluding(Matching.FromSource("Hangfire"))                    .CreateLogger();            } }}
查看完整描述

3 回答

?
斯蒂芬大帝

TA貢獻1827條經(jīng)驗 獲得超8個贊

定義一個不記錄任何內(nèi)容的記錄器和日志提供程序:


using Hangfire;

using Hangfire.Logging;


public class NoLoggingProvider : ILogProvider {

    public ILog GetLogger(string name) {

        return new NoLoggingLogger();

    }

}


public class NoLoggingLogger : ILog {

    public bool Log(LogLevel logLevel, Func<string> messageFunc, Exception exception = null) {

        return false;

    }

}

并配置 Hangfire 以在您的Startup課程中使用它:


using Hangfire;


public class Startup {

    public void Configuration(IAppBuilder app) {

        GlobalConfiguration.Configuration.UseLogProvider(new NoLoggingProvider());

        // the rest of your configuration...        

    }

}


查看完整回答
反對 回復 2022-01-09
?
慕標琳琳

TA貢獻1830條經(jīng)驗 獲得超9個贊

要開發(fā)@PatrickSteele 的答案,您似乎需要使用 SeriLog 的 SourceContent。Hangfire有很多這樣的。此代碼實現(xiàn)了這一點:


        Log.Logger = new LoggerConfiguration()

            .ReadFrom.Configuration(Configuration)

            .Filter.ByExcluding(Matching.FromSource("Hangfire.SqlServer.ExpirationManager"))

            .Filter.ByExcluding(Matching.FromSource("Hangfire.SqlServer.SqlServerObjectsInstaller"))

            .Filter.ByExcluding(Matching.FromSource("Hangfire.Server.BackgroundServerProcess"))

            .Filter.ByExcluding(Matching.FromSource("Hangfire.Server.ServerWatchdog"))

            .Filter.ByExcluding(Matching.FromSource("Hangfire.Server.ServerHeartbeatProcess"))

            .Filter.ByExcluding(Matching.FromSource("Hangfire.Processing.BackgroundExecution"))

            .Filter.ByExcluding(Matching.FromSource("Hangfire.SqlServer.CountersAggregator"))

            .Filter.ByExcluding(Matching.FromSource("Hangfire.BackgroundJobServer"))

            .CreateLogger();

當然,這是我的配置,它使用 SQL Server 作為日志記錄的目標。在這個地方收集來自 Hangfire 的各種資源以包含在您自己的代碼中可能會被證明是有用的(盡管這不一定是詳盡的)。


查看完整回答
反對 回復 2022-01-09
?
慕森卡

TA貢獻1806條經(jīng)驗 獲得超8個贊

對于點網(wǎng)核心,

在 appsettings.json 中,只需在“MinimumLevel => Override”下添加“Hangfire”,并將值設置為“ Warning ”。這只會記錄警告和錯誤。

如果您設置為“覆蓋”,那么它只會記錄來自hangfire的錯誤。

http://img1.sycdn.imooc.com//61daa2f800012b8610910784.jpg

查看完整回答
反對 回復 2022-01-09
  • 3 回答
  • 0 關注
  • 716 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號