Skip to content

Instantly share code, notes, and snippets.

@rsgoheen
Created February 27, 2015 13:44
Show Gist options
  • Save rsgoheen/ba5fb610396b09e4481e to your computer and use it in GitHub Desktop.
Save rsgoheen/ba5fb610396b09e4481e to your computer and use it in GitHub Desktop.
Using Serilog in a PowerShell script
Add-Type -Path "Serilog.dll"
Add-Type -Path "Serilog.Sinks.Seq.dll"
Add-Type -Path "Serilog.Sinks.EventLog.dll"
Add-Type -Path "Serilog.FullNetFx.dll"
Add-Type -Path "Serilog.Extras.AppSettings.dll"
Add-Type -Path "Serilog.Extras.Timing.dll"
$Config = New-Object Serilog.LoggerConfiguration
[Serilog.Configuration.LoggerSinkConfiguration]$ConfigSink = $config.WriteTo
[Serilog.Log]::Logger = [Serilog.LoggerConfigurationFullNetFxExtensions]::RollingFile($ConfigSink, "C:\Logs\Log-{Date}.txt", ([Serilog.Events.LogEventLevel]::Verbose), "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level}] {Message}{NewLine}{Exception}", $null, 10000000, 15).CreateLogger()
[Serilog.Log]::Information("Logging started")
@TomasBouda
Copy link

Hi, you might be intrested in module I wrote recently - https://github.com/PoShLog/PoShLog 😉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment