web.config asp.net mvc5のserilogAppSetting

サミー・サムモア

私はSerilogasp.net MVC 5に取り組んでいます。すべて正常に動作しますが、設定をコードではなくweb.configに移動したいと思います。データベース接続、ファイルパスを移動する必要があります。また、データベース用とファイル用の2つの異なるレベルを指定する必要があります。

これはコードです

 var logFileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, $"xxx.Web-{Environment.MachineName}.log");
            Log.Logger = new LoggerConfiguration()
                .MinimumLevel.Debug()
                .WriteTo.Trace(LogEventLevel.Debug, "{Timestamp:u} [{Level}] {SourceContext}:: {CorrelationId} {Message}{NewLine}{Exception}")
                .WriteTo.LiterateConsole(LogEventLevel.Debug, "{Timestamp:u} [{Level}] {SourceContext}:: {CorrelationId} {Message}{NewLine}{Exception}")
                .WriteTo.RollingFile(logFileName, LogEventLevel.Debug,
                    "{Timestamp:u} [{Level}] {MachineName} {SourceContext}:: {CorrelationId} {Message}{NewLine}{Exception}",
                    retainedFileCountLimit: 31, fileSizeLimitBytes: null)
                .WriteTo.MSSqlServer(connectionString, "LogUsers", LogEventLevel.Information)
                .Enrich.WithExceptionDetails()
                .Enrich.With<HttpRequestIdEnricher>()
                .Enrich.FromLogContext()
                .CreateLogger();

PSconnectionString変数はweb.configから取得されました。

私はセリログにとても慣れていないので、本当に混乱しています。できるだけ早く再生できる場合はお願いします。

ありがとうございました

ポール・カラム|

あなたがする必要があるのは、appSettingsWeb.Config内タグにSerilog情報を追加することです

<add key="serilog:using:MSSqlSever" value="Serilog.Sinks.MSSqlServer" />
<add key="serilog:write-to:MSSqlServer.connectionString" value="nameOfConnectionString" />
<add key="serilog:write-to:MSSqlServer.tableName" value="Serilogs" />
<add key="serilog:write-to:MSSqlServer.autoCreateSqlTable" value="true" />

上記のコードは、SQLデータベースへのログインに役立ちます。

<add key="serilog:using:File" value="Serilog.Sinks.File" />
<add key="serilog:write-to:File.path" value="log.txt" />
<add key="serilog:write-to:File.fileSizeLimitBytes" value="" />

そして、上記はあなたがテキストファイルに書くのを助けます。
コードで行う必要があるのは、log関数を呼び出すだけで、構成で指定したものに自動的にログを記録します。

さらにヘルプが必要な場合は、次の2つのページを
参照してください。https//github.com/serilog/serilog-sinks-mssqlserver
https://github.com/serilog/serilog-sinks-file

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

ASP.NET 5 MVC6のweb.config

分類Dev

ASP.NET Core2のweb.config

分類Dev

web.configのASP.NET5 / EF7接続文字列?

分類Dev

Using ELMAH inside my asp.net mvc 4 & MVC5 web application

分類Dev

How to programmatically modify web.config in ASP.NET MVC and C# application?

分類Dev

web.configのasp.net接続文字列の問題

分類Dev

web.config in ASP.NET Core 2

分類Dev

asp.net 4.6 MVC5の将来

分類Dev

ASP.Net MVC5のCookie

分類Dev

Asp.Net MVC5要素の選択

分類Dev

ASP .NET 5 wwwrootにweb.configが必要なのはなぜですか?

分類Dev

ASP.NET MVC5:RedirectToAction

分類Dev

AuthorizeAttribute ASP.NET Web.API MVC5のIsAuthorizedでPostパラメーターを取得する方法

分類Dev

Web.Config内のファイルへのASP.NET相対パス

分類Dev

asp.netコアのweb.configファイルの代替は何ですか

分類Dev

asp.netのweb.configへのハードコーディング

分類Dev

ASP.Net Identity Samples Web.Configのowin:AppStartupキーは何をしますか?

分類Dev

Asp .Net MVC5でiframeがWebサイトを表示しない

分類Dev

Angularjs + ASP.NET MVC + ASP.NET Web API

分類Dev

RazorViewのWeb.configからキー値にアクセスします-MVC3ASP.NET

分類Dev

ASP.net MVC Web Api + Android

分類Dev

DryIoc ASP.NET 5 Web API

分類Dev

ASP.NET web.config:configSourceとファイル属性

分類Dev

Issue when using ASP.Net web.config key as query parameter

分類Dev

ASP.NET-web.config認証を尊重しないJqueryload()

分類Dev

which http module will execute first in asp.net if both web and machine config has same modules registered

分類Dev

What does the owin:AppStartup key in the ASP.Net Identity Samples Web.Config do?

分類Dev

ASP.NET web.config Forms Authentication, deny anonymous users, allow anonymous access for single files

分類Dev

データベース接続: Web.config Asp.net

Related 関連記事

  1. 1

    ASP.NET 5 MVC6のweb.config

  2. 2

    ASP.NET Core2のweb.config

  3. 3

    web.configのASP.NET5 / EF7接続文字列?

  4. 4

    Using ELMAH inside my asp.net mvc 4 & MVC5 web application

  5. 5

    How to programmatically modify web.config in ASP.NET MVC and C# application?

  6. 6

    web.configのasp.net接続文字列の問題

  7. 7

    web.config in ASP.NET Core 2

  8. 8

    asp.net 4.6 MVC5の将来

  9. 9

    ASP.Net MVC5のCookie

  10. 10

    Asp.Net MVC5要素の選択

  11. 11

    ASP .NET 5 wwwrootにweb.configが必要なのはなぜですか?

  12. 12

    ASP.NET MVC5:RedirectToAction

  13. 13

    AuthorizeAttribute ASP.NET Web.API MVC5のIsAuthorizedでPostパラメーターを取得する方法

  14. 14

    Web.Config内のファイルへのASP.NET相対パス

  15. 15

    asp.netコアのweb.configファイルの代替は何ですか

  16. 16

    asp.netのweb.configへのハードコーディング

  17. 17

    ASP.Net Identity Samples Web.Configのowin:AppStartupキーは何をしますか?

  18. 18

    Asp .Net MVC5でiframeがWebサイトを表示しない

  19. 19

    Angularjs + ASP.NET MVC + ASP.NET Web API

  20. 20

    RazorViewのWeb.configからキー値にアクセスします-MVC3ASP.NET

  21. 21

    ASP.net MVC Web Api + Android

  22. 22

    DryIoc ASP.NET 5 Web API

  23. 23

    ASP.NET web.config:configSourceとファイル属性

  24. 24

    Issue when using ASP.Net web.config key as query parameter

  25. 25

    ASP.NET-web.config認証を尊重しないJqueryload()

  26. 26

    which http module will execute first in asp.net if both web and machine config has same modules registered

  27. 27

    What does the owin:AppStartup key in the ASP.Net Identity Samples Web.Config do?

  28. 28

    ASP.NET web.config Forms Authentication, deny anonymous users, allow anonymous access for single files

  29. 29

    データベース接続: Web.config Asp.net

ホットタグ

アーカイブ