c# - How to use ReadFrom.AppSettings in Serilog -
i discovered serilog , love it. however, i'm struggling read app.config.
code configuration:
ilogger logger = new loggerconfiguration() .readfrom.appsettings() //.minimumlevel.verbose() .enrich.withprocessid() .enrich.withthreadid() .enrich.withmachinename() .destructure.usingattributes() //.writeto.mssqlserver(@"server=evdvwadbv1;database=applog;trusted_connection=true;", "logs") .createlogger(); log.logger = logger;
the commented out sections configuration values want read config file.
the config file contains:
<appsettings> <add key="serilog:minimum-level" value="verbose"/> <add key="serilog:using" value="serilog.sinks.mssqlserver"/> <add key="serilog:write-to:mssqlserver.connectionstring" value="server=evdvwadbv1;database=applog;trusted_connection=true;"/> <add key="serilog:writeto:mssqlserver.tablename" value="logs"/> <add key="serilog:write-to:rollingfile.pathformat" value="c:\logs\myapp-{date}.txt" /> <add key="serilog:write-to:rollingfile.retainedfilecountlimit" value="10" /> </appsettings>
i'm using following serilog packages.
<package id="serilog" version="1.5.14" targetframework="net452" /> <package id="serilog.sinks.mssqlserver" version="3.0.41" targetframework="net452" />
i added first line of console app. i'm not seeing errors on console.
serilog.debugging.selflog.out = console.out;
what missing?
it looks may have typo in configuration:
serilog:writeto:mssqlserver.tablename
missing dash:
serilog:write-to:mssqlserver.tablename
Comments
Post a Comment