2016-06-13 143 views
1

我知道可以在app.config文件(AppSettings部分)中設置Serilog接收器,標量類型非常簡單,但是如何處理複雜類型(IFormatProvider等等。)。有人知道如何處理這個問題,有沒有可能?如何從app.config文件中設置Serilog中的formatProvider屬性

我試圖模仿這個例子

ILogger logger = new LoggerConfiguration() 
    .Enrich.WithExceptionDetails() 
    .WriteTo.Sink(new RollingFileSink(
     @"C:\logs", 
     new JsonFormatter(renderMessage: true)) 
    .CreateLogger(); 

,但只有使用的app.config。

回答

1

對此,您可以使用類似JsonRollingFile的東西。

<configuration> 
    <appSettings> 
    <add key="serilog:using:Json" value="Serilog.Sinks.Json" /> 
    <add key="serilog:write-to:JsonRollingFile.pathFormat" value="C:\Logs\myapp-{Date}.jsnl" /> 
    </appSettings> 
</configuration> 
+0

嗨@Nicholas Blumhardt, 因爲'JsonRollingFile'片已經過時的2.1+版本的,你怎麼能設置使用AppSettings配置JsonFormatter屬性renderMessage爲真? 我試過這樣,但它沒有工作: '

+0

嗨邁克爾 - 這裏有一個例子,應該有所幫助:https://github.com/serilog/serilog-formatting-compact#getting-started –

+0

嗨@Nicholas Blumhardt, 據我所知,這是關於'CompactJsonFormatter'。但是我想用'renderMessage'參數設置爲true的常規'JsonFormatter'。我找不到任何使用appsettings.config的示例。我在這裏錯過了什麼嗎?是不是可以通過XML配置來設置這個參數? –

相關問題