Skip to content

Commit

Permalink
Merge pull request #124 from serilog/dev
Browse files Browse the repository at this point in the history
3.0.0 Release
  • Loading branch information
nblumhardt authored Feb 29, 2024
2 parents 1e83316 + 568ac7f commit 573cb51
Show file tree
Hide file tree
Showing 26 changed files with 983 additions and 845 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ publish/
# Publish Web Output
*.[Pp]ublish.xml
*.azurePubxml
# TODO: Comment the next line if you want to checkin your web deploy settings
# TODO: Comment the next line if you want to checkin your web deploy settings
# but database connection strings (with potential passwords) will be unencrypted
*.pubxml
*.publishproj
Expand Down Expand Up @@ -183,3 +183,5 @@ UpgradeLog*.htm
# Microsoft Fakes
FakesAssemblies/
/.vs

.idea/
48 changes: 25 additions & 23 deletions Build.ps1
Original file line number Diff line number Diff line change
@@ -1,49 +1,51 @@
echo "build: Build started"
Write-Output "build: Build started"

& dotnet --info
& dotnet --list-sdks

Push-Location $PSScriptRoot

if(Test-Path .\artifacts) {
echo "build: Cleaning .\artifacts"
Write-Output "build: Cleaning .\artifacts"
Remove-Item .\artifacts -Force -Recurse
}

& dotnet restore --no-cache

$branch = @{ $true = $env:APPVEYOR_REPO_BRANCH; $false = $(git symbolic-ref --short -q HEAD) }[$env:APPVEYOR_REPO_BRANCH -ne $NULL];
$revision = @{ $true = "{0:00000}" -f [convert]::ToInt32("0" + $env:APPVEYOR_BUILD_NUMBER, 10); $false = "local" }[$env:APPVEYOR_BUILD_NUMBER -ne $NULL];
$suffix = @{ $true = ""; $false = "$($branch.Substring(0, [math]::Min(10,$branch.Length)))-$revision"}[$branch -eq "master" -and $revision -ne "local"]
$suffix = @{ $true = ""; $false = "$($branch.Substring(0, [math]::Min(10,$branch.Length)))-$revision"}[$branch -eq "main" -and $revision -ne "local"]
$commitHash = $(git rev-parse --short HEAD)
$buildSuffix = @{ $true = "$($suffix)-$($commitHash)"; $false = "$($branch)-$($commitHash)" }[$suffix -ne ""]

echo "build: Version suffix is $suffix"
echo "build: Build version suffix is $buildSuffix"
Write-Output "build: Package version suffix is $suffix"
Write-Output "build: Build version suffix is $buildSuffix"

foreach ($src in ls src/*) {
Push-Location $src
echo "build: Packaging project in $src"
foreach ($src in Get-ChildItem src/*) {
Push-Location $src

& dotnet build -c Release --version-suffix=$buildSuffix
Write-Output "build: Packaging project in $src"

if($suffix) {
& dotnet pack -c Release --no-build -o ..\..\artifacts --version-suffix=$suffix
} else {
& dotnet pack -c Release --no-build -o ..\..\artifacts
}
& dotnet build -c Release --version-suffix=$buildSuffix
if ($suffix) {
& dotnet pack -c Release --include-source -o ..\..\artifacts --version-suffix=$suffix --no-build
} else {
& dotnet pack -c Release --include-source -o ..\..\artifacts --no-build
}
if($LASTEXITCODE -ne 0) { throw "failed" }

if($LASTEXITCODE -ne 0) { exit 1 }

Pop-Location
Pop-Location
}

foreach ($test in ls test/*.Tests) {
Push-Location $test
echo "build: Testing project in $test"
& dotnet test -c Release
if($LASTEXITCODE -ne 0) { exit 3 }
Pop-Location
foreach ($test in Get-ChildItem test/*.Tests) {
Push-Location $test

Write-Output "build: Testing project in $test"

& dotnet test -c Release
if($LASTEXITCODE -ne 0) { throw "failed" }

Pop-Location
}

Pop-Location
11 changes: 0 additions & 11 deletions CHANGES.md

This file was deleted.

101 changes: 94 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,106 @@
# Serilog.Sinks.Email

[![Build status](https://ci.appveyor.com/api/projects/status/sfvp7dw8u6aiodj1/branch/master?svg=true)](https://ci.appveyor.com/project/serilog/serilog-sinks-email/branch/master)
[![Build status](https://ci.appveyor.com/api/projects/status/sfvp7dw8u6aiodj1/branch/main?svg=true)](https://ci.appveyor.com/project/serilog/serilog-sinks-email/branch/main)

Sends log events by SMTP email.

**Package** - [Serilog.Sinks.Email](http://nuget.org/packages/serilog.sinks.email)
| **Platforms** - .NET 4.5

```csharp
var log = new LoggerConfiguration()
await using var log = new LoggerConfiguration()
.WriteTo.Email(
fromEmail: "[email protected]",
toEmail: "[email protected]",
mailServer: "smtp.example.com")
from: "[email protected]",
to: "[email protected]",
host: "smtp.example.com")
.CreateLogger();
```

An overload accepting `EmailConnectionInfo` can be used to specify advanced options.
Supported options are:

| Parameter | Description |
|------------------------|-------------------------------------------------------------------------------------------------------------------------------------|
| `from` | The email address emails will be sent from. |
| `to` | The email address emails will be sent to. Multiple addresses can be separated with commas or semicolons. |
| `host` | The SMTP server to use. |
| `port` | The port used for the SMTP connection. The default is 25. |
| `connectionSecurity` | Choose the security applied to the SMTP connection. This enumeration type is supplied by MailKit. The default is `Auto`. |
| `credentials` | The network credentials to use to authenticate with the mail server. |
| `subject` | A message template describing the email subject. The default is `"Log Messages"`. |
| `body` | A message template describing the format of the email body. The default is `"{Timestamp} [{Level}] {Message}{NewLine}{Exception}"`. |
| `formatProvider` | Supplies culture-specific formatting information. The default is to use the current culture. |

An overload accepting `EmailSinkOptions` can be used to specify advanced options such as batched and/or HTML body templates.

## Sending batch email

To send batch email, supply `WriteTo.Email` with a batch size:

```csharp
await using var log = new LoggerConfiguration()
.WriteTo.Email(
options: new()
{
From = "[email protected]",
To = "[email protected]",
Host = "smtp.example.com",
},
batchingOptions: new()
{
BatchSizeLimit = 10,
Period = TimeSpan.FromSeconds(30),
})
.CreateLogger();
```

Batch formatting can be customized using `options.Body`.

## Sending HTML email

To send HTML email, specify a custom `IBatchTextFormatter` in `options.Body` and set `options.IsBodyHtml` to `true`:


```csharp
await using var log = new LoggerConfiguration()
.WriteTo.Email(
options: new()
{
From = "[email protected]",
To = "[email protected]",
Host = "smtp.example.com",
Body = new MyHtmlBodyFormatter(),
IsBodyHtml = true,
},
batchingOptions: new()
{
BatchSizeLimit = 10,
Period = TimeSpan.FromSeconds(30),
})
.CreateLogger();
```

A simplistic HTML formatter is shown below:

```csharp
class MyHtmlBodyFormatter : IBatchTextFormatter
{
public void FormatBatch(IEnumerable<LogEvent> logEvents, TextWriter output)
{
output.Write("<table>");
foreach (var logEvent in logEvents)
{
output.Write("<tr>");
Format(logEvent, output);
output.Write("</tr>");
}

output.Write("</table>");
}

public void Format(LogEvent logEvent, TextWriter output)
{
using var buffer = new StringWriter();
logEvent.RenderMessage(buffer);
output.Write(WebUtility.HtmlEncode(buffer.ToString()));
}
}
```
50 changes: 17 additions & 33 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,39 +1,23 @@
version: '{build}'
skip_tags: true
image:
- Visual Studio 2019
- Ubuntu
configuration: Release
image: Visual Studio 2022
test: off
#install:
#- ps: ./Setup.ps1
build_script:
- ps: ./Build.ps1
for:
-
matrix:
only:
- image: Ubuntu
# install:
# - sh setup.sh
build_script:
- sh build.sh
- pwsh: ./Build.ps1
artifacts:
- path: artifacts/Serilog.*.nupkg
- path: artifacts/Serilog.*.snupkg
- path: artifacts/Serilog.*.nupkg
deploy:
- provider: NuGet
api_key:
secure: K3/810hkTO6rd2AEHVkUQAadjGmDREus9k96QHu6hxrA1/wRTuAJemHMKtVVgIvf
skip_symbols: true
on:
branch: /^(master|dev)$/
- provider: GitHub
auth_token:
secure: p4LpVhBKxGS5WqucHxFQ5c7C8cP74kbNB0Z8k9Oxx/PMaDQ1+ibmoexNqVU5ZlmX
artifact:
/Serilog.*\.nupkg/
/Serilog.*\.snupkg/
tag: v$(appveyor_build_version)
on:
branch: master
- provider: NuGet
api_key:
secure: sDnchSg4TZIOK7oIUI6BJwFPNENTOZrGNsroGO1hehLJSvlHpFmpTwiX8+bgPD+Q
skip_symbols: true
on:
branch: /^(main|dev)$/
- provider: GitHub
auth_token:
secure: p4LpVhBKxGS5WqucHxFQ5c7C8cP74kbNB0Z8k9Oxx/PMaDQ1+ibmoexNqVU5ZlmX
artifact: /Serilog.*\.nupkg/
tag: v$(appveyor_build_version)
on:
branch: main

2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"sdk": {
"allowPrerelease": false,
"version": "3.1.100",
"version": "8.0.100",
"rollForward": "latestFeature"
}
}
19 changes: 15 additions & 4 deletions serilog-sinks-email.sln
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "assets", "assets", "{DACEA9
.gitignore = .gitignore
appveyor.yml = appveyor.yml
Build.ps1 = Build.ps1
build.sh = build.sh
CHANGES.md = CHANGES.md
Directory.Build.props = Directory.Build.props
global.json = global.json
README.md = README.md
assets\Serilog.snk = assets\Serilog.snk
Setup.ps1 = Setup.ps1
setup.sh = setup.sh
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{340DBC35-BD09-414B-818C-978FBCA4CDF1}"
Expand All @@ -27,6 +23,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Serilog.Sinks.Email.Tests",
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Serilog.Sinks.Email", "src\Serilog.Sinks.Email\Serilog.Sinks.Email.csproj", "{96A53337-1692-4884-BE03-34A97147EACE}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestHarness", "test\TestHarness\TestHarness.csproj", "{31356ADE-0243-4286-9187-C4A398BD4887}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -61,13 +59,26 @@ Global
{96A53337-1692-4884-BE03-34A97147EACE}.Release|x64.Build.0 = Release|Any CPU
{96A53337-1692-4884-BE03-34A97147EACE}.Release|x86.ActiveCfg = Release|Any CPU
{96A53337-1692-4884-BE03-34A97147EACE}.Release|x86.Build.0 = Release|Any CPU
{31356ADE-0243-4286-9187-C4A398BD4887}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{31356ADE-0243-4286-9187-C4A398BD4887}.Debug|Any CPU.Build.0 = Debug|Any CPU
{31356ADE-0243-4286-9187-C4A398BD4887}.Debug|x64.ActiveCfg = Debug|Any CPU
{31356ADE-0243-4286-9187-C4A398BD4887}.Debug|x64.Build.0 = Debug|Any CPU
{31356ADE-0243-4286-9187-C4A398BD4887}.Debug|x86.ActiveCfg = Debug|Any CPU
{31356ADE-0243-4286-9187-C4A398BD4887}.Debug|x86.Build.0 = Debug|Any CPU
{31356ADE-0243-4286-9187-C4A398BD4887}.Release|Any CPU.ActiveCfg = Release|Any CPU
{31356ADE-0243-4286-9187-C4A398BD4887}.Release|Any CPU.Build.0 = Release|Any CPU
{31356ADE-0243-4286-9187-C4A398BD4887}.Release|x64.ActiveCfg = Release|Any CPU
{31356ADE-0243-4286-9187-C4A398BD4887}.Release|x64.Build.0 = Release|Any CPU
{31356ADE-0243-4286-9187-C4A398BD4887}.Release|x86.ActiveCfg = Release|Any CPU
{31356ADE-0243-4286-9187-C4A398BD4887}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{7BC4F72D-F40B-4F7C-8EBD-E50F0D6C0D97} = {70D17E86-9325-4228-8512-547B3E0774A1}
{96A53337-1692-4884-BE03-34A97147EACE} = {340DBC35-BD09-414B-818C-978FBCA4CDF1}
{31356ADE-0243-4286-9187-C4A398BD4887} = {70D17E86-9325-4228-8512-547B3E0774A1}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {9E7E183E-7DDE-45DB-ACE9-2055FB3B7847}
Expand Down
Loading

0 comments on commit 573cb51

Please sign in to comment.