I RTFM'd
Nuget version: Serilog.2.0.0-beta-541
Win 7 x64
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
using System.Windows;
using Serilog;
using Serilog.Settings; // greyed out in my Visual Studio
// ...
protected override void OnStartup(StartupEventArgs e)
{
Log.Logger = new LoggerConfiguration()
.ReadFrom.AppSettings()
.CreateLogger();
// ...
}
Error CS1061 'LoggerSettingsConfiguration' does not contain a definition for 'AppSettings' and no extension method 'AppSettings' accepting a first argument of type 'LoggerSettingsConfiguration' could be found (are you missing a using directive or an assembly reference?)
I bet I missed something really obvious. What is it?
uh, looks like it might be an App.config problem
Message=Only one
Source=System.Configuration
BareMessage=Only one
.... edit ... uh, nup - fixed that. it was just in the wrong order.
perhaps this? https://github.com/serilog/serilog/commit/03c8dfb6ba4c3528b5cd458ba2351dd8f43d0028
or do I need https://www.nuget.org/packages/Serilog.Extras.AppSettings/ ? which is marked as obsolete and it's empty
oh, ok - build this and add it: https://github.com/serilog/serilog-settings-appsettings
or not. Nup. Reverting to settings in code for now.
This didn't work for me ...
<appSettings>
<add key="serilog:minimum-level" value="Verbose" />
<add key="serilog:enrich:with-property:Application" value="tvCADdesktop" />
<add key="serilog:enrich:with-property:Version" value="1.0" />
<add key="serilog:write-to:RollingFile.pathFormat" value="%APPDATA%\CADbloke\tvCADdesktop\Logs\tvCADdesktop-{Date}.txt" />
<add key="serilog:write-to:RollingFile.retainedFileCountLimit" value="15" />
<add key="serilog:using:Seq" value="Serilog.Sinks.Seq" />
<add key="serilog:write-to:Seq.serverUrl" value="http://localhost:5341" />
<add key="serilog:write-to:Seq.restrictedToMinimumLevel" value="Information" />
</appSettings>
Thanks for the note Ewen! Once RC2 is out we'll run across all the documentation and get it straightened out, sorry about the pain.
You need:
Install-Package Serilog.Settings.AppSettings -Pre
Cheers!
Fixed!. Ta.
While you're on docs, on the page I linked to at the top about XML config could do with a little clarification, the RollingFile sink needed this...
<add key="serilog:using:RollingFile" value="Serilog.Sinks.RollingFile" />
Perhaps a pro-forma example is needed to show the common syntax for configuring a Sink, something like ...
<add key="serilog:using:{key}" value="Serilog.Sinks.{SinkName}" />
<add key="serilog:write-to:{Key).{propertyParameterName}" value="{yourValue}" />
if indeed the {propertyParameterName}
is the correct syntax (it was just my guess).
As for pain, Mate, you and Serilog have saved me an immeasurable amount of pain compared to this simple config issue. Thanks for writing Serilog.
cheers
Ewen
a p.s. for anyone stumbling across this, here is the first bit of my App.config
for an App that also has Entity Framework + SQLite etc. The config writes verbose logs to a file and Information & above to Seq. Note, it is essential that <configSections> ... <.configSections>
is the first child of <configuration>
. Hope this helps ...
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=hahahahano" requirePermission="false" />
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=hahahahano">
<section name="tvCADdesktop.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=hahahahano" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
</sectionGroup>
</configSections>
<appSettings>
<add key="serilog:minimum-level" value="Verbose" />
<add key="serilog:enrich:with-property:Application" value="tvCADdesktop" />
<add key="serilog:enrich:with-property:Version" value="1.0" />
<add key="serilog:using:RollingFile" value="Serilog.Sinks.RollingFile" />
<add key="serilog:write-to:RollingFile.pathFormat" value="%APPDATA%\CADbloke\tvCADdesktop\Logs\tvCADdesktop-{Date}.txt" />
<add key="serilog:write-to:RollingFile.retainedFileCountLimit" value="15" />
<add key="serilog:using:Seq" value="Serilog.Sinks.Seq" />
<add key="serilog:write-to:Seq.serverUrl" value="http://localhost:5341" />
<add key="serilog:write-to:Seq.restrictedToMinimumLevel" value="Information" />
</appSettings>
...
Bonus tip for reading all the way to the end - https://github.com/RolandPheasant/TailBlazer is the best thing ever for reading text logs
Most helpful comment
Fixed!. Ta.
While you're on docs, on the page I linked to at the top about XML config could do with a little clarification, the RollingFile sink needed this...
Perhaps a pro-forma example is needed to show the common syntax for configuring a Sink, something like ...
if indeed the
{propertyParameterName}
is the correct syntax (it was just my guess).As for pain, Mate, you and Serilog have saved me an immeasurable amount of pain compared to this simple config issue. Thanks for writing Serilog.
cheers
Ewen
a p.s. for anyone stumbling across this, here is the first bit of my
App.config
for an App that also has Entity Framework + SQLite etc. The config writes verbose logs to a file and Information & above to Seq. Note, it is essential that<configSections> ... <.configSections>
is the first child of<configuration>
. Hope this helps ...Bonus tip for reading all the way to the end - https://github.com/RolandPheasant/TailBlazer is the best thing ever for reading text logs