├── .gitattributes ├── .github ├── ISSUE_TEMPLATE.md └── PULL_REQUEST_TEMPLATE.md ├── .gitignore ├── Build.ps1 ├── CHANGES.md ├── LICENSE ├── README.md ├── appveyor.yml ├── artifacts └── .gitkeep ├── assets ├── Serilog.snk └── serilog-sink-nuget.png ├── global.json ├── serilog-sinks-xamarin.sln ├── src └── Serilog.Sinks.Xamarin │ ├── Serilog.Sinks.Xamarin.csproj │ └── Sinks │ └── Xamarin │ ├── android │ ├── AndroidLogSink.cs │ └── LoggerConfigurationXamarinExtensions.cs │ └── apple-common │ ├── LoggerConfigurationXamarinExtensions.cs │ └── NSLogSink.cs └── test └── Blank.txt /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | 3 | * text=auto 4 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | ***Note*: for support questions, please ask on StackOverflow: https://stackoverflow.com/questions/tagged/serilog . This repository's issues are reserved for feature requests and bug reports.** 2 | 3 | **Do you want to request a *feature* or report a *bug*?** 4 | 5 | 6 | 7 | **What is the current behavior?** 8 | 9 | 10 | 11 | **If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem** 12 | 13 | 14 | 15 | **What is the expected behavior?** 16 | 17 | 18 | 19 | **What is the motivation / use case for changing the behavior?** 20 | 21 | 22 | 23 | **Which versions of Serilog, and which platform / OS are affected by this issue? Did this work in previous versions of Serilog?** 24 | 25 | 26 | 27 | **Other information (e.g. stacktraces, related issues, suggestions how to fix)** 28 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | **What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)** 2 | 3 | 4 | 5 | **What is the current behavior? (You can also link to an open issue here)** 6 | 7 | 8 | 9 | **What is the new behavior (if this is a feature change)?** 10 | 11 | 12 | 13 | **Does this PR introduce a breaking change?** 14 | 15 | 16 | 17 | **Please check if the PR fulfills these requirements** 18 | - [ ] The commit follows our guidelines: https://github.com/serilog/serilog#contribute 19 | - [ ] Tests for the changes have been added (for bug fixes / features) 20 | - [ ] Docs have been added / updated (for bug fixes / features) 21 | 22 | **Other information**: 23 | 24 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.sln.docstates 8 | 9 | # Build results 10 | [Dd]ebug/ 11 | [Dd]ebugPublic/ 12 | [Rr]elease/ 13 | [Rr]eleases/ 14 | x64/ 15 | x86/ 16 | build/ 17 | bld/ 18 | [Bb]in/ 19 | [Oo]bj/ 20 | 21 | # Roslyn cache directories 22 | *.ide/ 23 | 24 | # MSTest test Results 25 | [Tt]est[Rr]esult*/ 26 | [Bb]uild[Ll]og.* 27 | 28 | #NUNIT 29 | *.VisualState.xml 30 | TestResult.xml 31 | 32 | # Build Results of an ATL Project 33 | [Dd]ebugPS/ 34 | [Rr]eleasePS/ 35 | dlldata.c 36 | 37 | *_i.c 38 | *_p.c 39 | *_i.h 40 | *.ilk 41 | *.meta 42 | *.obj 43 | *.pch 44 | *.pdb 45 | *.pgc 46 | *.pgd 47 | *.rsp 48 | *.sbr 49 | *.tlb 50 | *.tli 51 | *.tlh 52 | *.tmp 53 | *.tmp_proj 54 | *.log 55 | *.vspscc 56 | *.vssscc 57 | .builds 58 | *.pidb 59 | *.svclog 60 | *.scc 61 | 62 | # Chutzpah Test files 63 | _Chutzpah* 64 | 65 | # Visual C++ cache files 66 | ipch/ 67 | *.aps 68 | *.ncb 69 | *.opensdf 70 | *.sdf 71 | *.cachefile 72 | 73 | # Visual Studio profiler 74 | *.psess 75 | *.vsp 76 | *.vspx 77 | 78 | # TFS 2012 Local Workspace 79 | $tf/ 80 | 81 | # Guidance Automation Toolkit 82 | *.gpState 83 | 84 | # ReSharper is a .NET coding add-in 85 | _ReSharper*/ 86 | *.[Rr]e[Ss]harper 87 | *.DotSettings.user 88 | 89 | # JustCode is a .NET coding addin-in 90 | .JustCode 91 | 92 | # TeamCity is a build add-in 93 | _TeamCity* 94 | 95 | # DotCover is a Code Coverage Tool 96 | *.dotCover 97 | 98 | # NCrunch 99 | _NCrunch_* 100 | .*crunch*.local.xml 101 | 102 | # MightyMoose 103 | *.mm.* 104 | AutoTest.Net/ 105 | 106 | # Web workbench (sass) 107 | .sass-cache/ 108 | 109 | # Installshield output folder 110 | [Ee]xpress/ 111 | 112 | # DocProject is a documentation generator add-in 113 | DocProject/buildhelp/ 114 | DocProject/Help/*.HxT 115 | DocProject/Help/*.HxC 116 | DocProject/Help/*.hhc 117 | DocProject/Help/*.hhk 118 | DocProject/Help/*.hhp 119 | DocProject/Help/Html2 120 | DocProject/Help/html 121 | 122 | # Click-Once directory 123 | publish/ 124 | 125 | # Publish Web Output 126 | *.[Pp]ublish.xml 127 | *.azurePubxml 128 | # TODO: Comment the next line if you want to checkin your web deploy settings 129 | # but database connection strings (with potential passwords) will be unencrypted 130 | *.pubxml 131 | *.publishproj 132 | 133 | # NuGet Packages 134 | *.nupkg 135 | # The packages folder can be ignored because of Package Restore 136 | **/packages/* 137 | # except build/, which is used as an MSBuild target. 138 | !**/packages/build/ 139 | # If using the old MSBuild-Integrated Package Restore, uncomment this: 140 | #!**/packages/repositories.config 141 | 142 | # Windows Azure Build Output 143 | csx/ 144 | *.build.csdef 145 | 146 | # Windows Store app package directory 147 | AppPackages/ 148 | 149 | # Others 150 | sql/ 151 | *.Cache 152 | ClientBin/ 153 | [Ss]tyle[Cc]op.* 154 | ~$* 155 | *~ 156 | *.dbmdl 157 | *.dbproj.schemaview 158 | *.pfx 159 | *.publishsettings 160 | node_modules/ 161 | 162 | # RIA/Silverlight projects 163 | Generated_Code/ 164 | 165 | # Backup & report files from converting an old project file 166 | # to a newer Visual Studio version. Backup files are not needed, 167 | # because we have git ;-) 168 | _UpgradeReport_Files/ 169 | Backup*/ 170 | UpgradeLog*.XML 171 | UpgradeLog*.htm 172 | 173 | # SQL Server files 174 | *.mdf 175 | *.ldf 176 | 177 | # Business Intelligence projects 178 | *.rdl.data 179 | *.bim.layout 180 | *.bim_*.settings 181 | 182 | # Microsoft Fakes 183 | FakesAssemblies/ 184 | 185 | # Xamarin.Android Resource.Designer.cs files 186 | **/*.Android/**/[Rr]esource.[Dd]esigner.cs 187 | **/*.Droid/**/[Rr]esource.[Dd]esigner.cs 188 | **/Android/**/[Rr]esource.[Dd]esigner.cs 189 | **/Droid/**/[Rr]esource.[Dd]esigner.cs 190 | 191 | # JetBrains Rider 192 | .idea 193 | 194 | # macOS 195 | .DS_Store 196 | /.vs 197 | -------------------------------------------------------------------------------- /Build.ps1: -------------------------------------------------------------------------------- 1 | echo "build: Build started" 2 | 3 | Push-Location $PSScriptRoot 4 | 5 | if(Test-Path .\artifacts) { 6 | echo "build: Cleaning .\artifacts" 7 | Remove-Item .\artifacts -Force -Recurse 8 | } 9 | 10 | $branch = @{ $true = $env:APPVEYOR_REPO_BRANCH; $false = $(git symbolic-ref --short -q HEAD) }[$env:APPVEYOR_REPO_BRANCH -ne $NULL]; 11 | $revision = @{ $true = "{0:00000}" -f [convert]::ToInt32("0" + $env:APPVEYOR_BUILD_NUMBER, 10); $false = "local" }[$env:APPVEYOR_BUILD_NUMBER -ne $NULL]; 12 | $suffix = @{ $true = ""; $false = "$($branch.Substring(0, [math]::Min(10,$branch.Length)))-$revision"}[$branch -eq "main" -and $revision -ne "local"] 13 | $commitHash = $(git rev-parse --short HEAD) 14 | $buildSuffix = @{ $true = "$($suffix)-$($commitHash)"; $false = "$($branch)-$($commitHash)" }[$suffix -ne ""] 15 | 16 | echo "build: Package version suffix is $suffix" 17 | echo "build: Build version suffix is $buildSuffix" 18 | 19 | foreach ($src in ls src/*) { 20 | Push-Location $src 21 | 22 | echo "build: Packaging project in $src" 23 | 24 | & msbuild /r /m /p:Configuration=Release /p:VersionSuffix=$suffix /p:EnableSourceLink=true "/p:PackageOutputPath=..\..\artifacts" 25 | 26 | if($LASTEXITCODE -ne 0) { exit 1 } 27 | 28 | Pop-Location 29 | } 30 | 31 | foreach ($test in ls test/*.Tests) { 32 | Push-Location $test 33 | 34 | echo "build: Testing project in $test" 35 | 36 | & dotnet test -c Release 37 | if($LASTEXITCODE -ne 0) { exit 3 } 38 | 39 | Pop-Location 40 | } 41 | 42 | Pop-Location 43 | -------------------------------------------------------------------------------- /CHANGES.md: -------------------------------------------------------------------------------- 1 | 1.5 2 | * Moved from serilog/serilog 3 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | 203 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Serilog.Sinks.Xamarin [![Build status](https://ci.appveyor.com/api/projects/status/8iy9owuib92gvtix?svg=true)](https://ci.appveyor.com/project/serilog/serilog-sinks-xamarin) [![Join the chat at https://gitter.im/serilog/serilog](https://img.shields.io/gitter/room/serilog/serilog.svg)](https://gitter.im/serilog/serilog) 2 | 3 | Writes [Serilog](https://serilog.net) events to the console of Xamarin.iOS (NSLog) / Xamarin.Android (AndroidLog). 4 | 5 | ### Getting started 6 | 7 | Install from [NuGet](https://nuget.org/packages/serilog.sinks.xamarin): 8 | 9 | ```powershell 10 | Install-Package Serilog.Sinks.Xamarin 11 | ``` 12 | 13 | When using Xamarin.iOS 14 | 15 | ```csharp 16 | Log.Logger = new LoggerConfiguration() 17 | .WriteTo.NSLog() 18 | .CreateLogger(); 19 | ``` 20 | 21 | When using Xamarin.Android 22 | 23 | 24 | ```csharp 25 | Log.Logger = new LoggerConfiguration() 26 | .WriteTo.AndroidLog() 27 | .Enrich.WithProperty(Constants.SourceContextPropertyName, "MyCustomTag") //Sets the Tag field. 28 | .CreateLogger(); 29 | ``` 30 | 31 | Within your portable class libary or within your application 32 | 33 | ```csharp 34 | Log.Information("This will be written to either NSLog or AndroidLog"); 35 | 36 | ``` 37 | 38 | Because the memory buffer may contain events that have not yet been written to the target sink, it is important to call `Log.CloseAndFlush()` or `Logger.Dispose()` when the application/activity exits. 39 | -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | version: '{build}' 2 | skip_tags: true 3 | image: Visual Studio 2022 4 | configuration: Release 5 | install: 6 | - ps: mkdir -Force ".\build\" | Out-Null 7 | - cmd: dotnet workload install maui macos android ios maccatalyst 8 | - ps: mkdir -Force ".\artifacts\" | Out-Null 9 | build_script: 10 | - ps: ./Build.ps1 11 | test: off 12 | artifacts: 13 | - path: artifacts/Serilog.*.nupkg 14 | deploy: 15 | - provider: NuGet 16 | api_key: 17 | secure: 1vfQHBQJGc6+0gH8WeuPc2mcD8aAIih+umHmgR8V8tP4dGCs90uD70cbiY2oISAj 18 | skip_symbols: true 19 | on: 20 | branch: /^(main|dev)$/ 21 | - provider: GitHub 22 | auth_token: 23 | secure: p4LpVhBKxGS5WqucHxFQ5c7C8cP74kbNB0Z8k9Oxx/PMaDQ1+ibmoexNqVU5ZlmX 24 | artifact: /Serilog.*\.nupkg/ 25 | tag: v$(appveyor_build_version) 26 | on: 27 | branch: main 28 | -------------------------------------------------------------------------------- /artifacts/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serilog/serilog-sinks-xamarin/0beb06a55c5d0c91a3727f0b3de9c9c1e0c3b198/artifacts/.gitkeep -------------------------------------------------------------------------------- /assets/Serilog.snk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serilog/serilog-sinks-xamarin/0beb06a55c5d0c91a3727f0b3de9c9c1e0c3b198/assets/Serilog.snk -------------------------------------------------------------------------------- /assets/serilog-sink-nuget.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serilog/serilog-sinks-xamarin/0beb06a55c5d0c91a3727f0b3de9c9c1e0c3b198/assets/serilog-sink-nuget.png -------------------------------------------------------------------------------- /global.json: -------------------------------------------------------------------------------- 1 | { 2 | "msbuild-sdks": { 3 | "MSBuild.Sdk.Extras": "3.0.44" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /serilog-sinks-xamarin.sln: -------------------------------------------------------------------------------- 1 | Microsoft Visual Studio Solution File, Format Version 12.00 2 | # Visual Studio Version 17 3 | VisualStudioVersion = 17.3.32708.82 4 | MinimumVisualStudioVersion = 10.0.40219.1 5 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "sln", "sln", "{322FD05A-A274-4AF2-99CA-BCCB0B4400F5}" 6 | ProjectSection(SolutionItems) = preProject 7 | appveyor.yml = appveyor.yml 8 | Build.ps1 = Build.ps1 9 | .gitignore = .gitignore 10 | CHANGES.md = CHANGES.md 11 | global.json = global.json 12 | LICENSE = LICENSE 13 | README.md = README.md 14 | EndProjectSection 15 | EndProject 16 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Serilog.Sinks.Xamarin", "src\Serilog.Sinks.Xamarin\Serilog.Sinks.Xamarin.csproj", "{717384AC-F5BC-44BE-92B0-CC7DAF50CB8A}" 17 | EndProject 18 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{B2CE2F52-1413-4B3D-86CB-555235E9B71C}" 19 | EndProject 20 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{8D712A90-44C6-47F4-9746-2D21743137CE}" 21 | EndProject 22 | Global 23 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 24 | Debug|Any CPU = Debug|Any CPU 25 | Release|Any CPU = Release|Any CPU 26 | EndGlobalSection 27 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 28 | {717384AC-F5BC-44BE-92B0-CC7DAF50CB8A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 29 | {717384AC-F5BC-44BE-92B0-CC7DAF50CB8A}.Debug|Any CPU.Build.0 = Debug|Any CPU 30 | {717384AC-F5BC-44BE-92B0-CC7DAF50CB8A}.Release|Any CPU.ActiveCfg = Release|Any CPU 31 | {717384AC-F5BC-44BE-92B0-CC7DAF50CB8A}.Release|Any CPU.Build.0 = Release|Any CPU 32 | EndGlobalSection 33 | GlobalSection(SolutionProperties) = preSolution 34 | HideSolutionNode = FALSE 35 | EndGlobalSection 36 | GlobalSection(NestedProjects) = preSolution 37 | {717384AC-F5BC-44BE-92B0-CC7DAF50CB8A} = {B2CE2F52-1413-4B3D-86CB-555235E9B71C} 38 | GlobalSection(ExtensibilityGlobals) = postSolution 39 | SolutionGuid = {37019599-01BF-43D7-BE49-21A7A56EC8E2} 40 | EndGlobalSection 41 | EndGlobal 42 | -------------------------------------------------------------------------------- /src/Serilog.Sinks.Xamarin/Serilog.Sinks.Xamarin.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | A Serilog sink that writes log events to Xamarin Android AndroidLogger and/or Xamarin iOS or Xamarin macOS NSLog. 5 | 1.0.0 6 | Serilog Contributors 7 | Xamarin.iOS10;Xamarin.Mac20;MonoAndroid90;net6.0-ios;net6.0-macos;net6.0-android;net6.0-maccatalyst 8 | ../../assets/Serilog.snk 9 | true 10 | true 11 | serilog;xamarin;android;androidlogger;monodroid;monotouch;ios;macos;nslog 12 | images\icon.png 13 | https://github.com/serilog/serilog-sinks-xamarin 14 | Apache-2.0 15 | https://github.com/serilog/serilog-sinks-xamarin 16 | git 17 | True 18 | 19 | Serilog 20 | true 21 | 22 | 23 | 24 | false 25 | true 26 | 27 | false 28 | true 29 | 30 | false 31 | true 32 | 33 | <_IsAndroid>false 34 | <_IsAndroid Condition="$(IsMonoAndroid) or '$(TargetFramework)'=='net6.0-android'">true 35 | 36 | <_IsCatalyst>false 37 | <_IsCatalyst Condition="$(_IsCatalyst) or '$(TargetFramework)'=='net6.0-maccatalyst'">true 38 | 39 | <_IsIOS>false 40 | <_IsIOS Condition="$(IsXamarinIOS) or '$(TargetFramework)'=='net6.0-ios'">true 41 | 42 | <_IsMacOS>false 43 | <_IsMacOS Condition="$(IsXamarinMac) or '$(TargetFramework)'=='net6.0-macos'">true 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | -------------------------------------------------------------------------------- /src/Serilog.Sinks.Xamarin/Sinks/Xamarin/android/AndroidLogSink.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2015 Serilog Contributors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using System; 16 | using System.IO; 17 | using System.Linq; 18 | using Android.Util; 19 | using Serilog.Core; 20 | using Serilog.Events; 21 | using Serilog.Formatting; 22 | using AndroidLog = Android.Util.Log; 23 | 24 | namespace Serilog.Sinks.Xamarin 25 | { 26 | /// 27 | /// Writes events to . 28 | /// 29 | public class AndroidLogSink : ILogEventSink 30 | { 31 | private readonly ITextFormatter _textFormatter; 32 | 33 | /// 34 | /// Create an instance with the provided . 35 | /// 36 | /// Formatter for log events 37 | /// The text formatter must be provided 38 | public AndroidLogSink(ITextFormatter textFormatter) 39 | { 40 | if (textFormatter == null) throw new ArgumentNullException("textFormatter"); 41 | _textFormatter = textFormatter; 42 | } 43 | 44 | /// 45 | /// Emit the provided log event to the sink. 46 | /// 47 | /// The log event to write. 48 | public void Emit(LogEvent logEvent) 49 | { 50 | if (logEvent == null) throw new ArgumentNullException("logEvent"); 51 | var renderSpace = new StringWriter(); 52 | _textFormatter.Format(logEvent, renderSpace); 53 | 54 | var tag = logEvent.Properties.Where(x => x.Key == Constants.SourceContextPropertyName).Select(x => x.Value.ToString("l", null)).FirstOrDefault() ?? ""; 55 | 56 | switch (logEvent.Level) { 57 | case LogEventLevel.Debug: 58 | AndroidLog.Debug(tag, renderSpace.ToString()); 59 | break; 60 | 61 | case LogEventLevel.Information: 62 | AndroidLog.Info(tag, renderSpace.ToString()); 63 | break; 64 | 65 | case LogEventLevel.Verbose: 66 | AndroidLog.Verbose(tag, renderSpace.ToString()); 67 | break; 68 | 69 | case LogEventLevel.Warning: 70 | AndroidLog.Warn(tag, renderSpace.ToString()); 71 | break; 72 | 73 | case LogEventLevel.Error: 74 | AndroidLog.Error(tag, renderSpace.ToString()); 75 | break; 76 | 77 | case LogEventLevel.Fatal: 78 | AndroidLog.Wtf(tag, renderSpace.ToString()); 79 | break; 80 | 81 | default: 82 | AndroidLog.WriteLine(LogPriority.Assert, tag, renderSpace.ToString()); 83 | break; 84 | } 85 | } 86 | } 87 | } -------------------------------------------------------------------------------- /src/Serilog.Sinks.Xamarin/Sinks/Xamarin/android/LoggerConfigurationXamarinExtensions.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Serilog Contributors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using System; 16 | using Serilog.Configuration; 17 | using Serilog.Events; 18 | using Serilog.Formatting.Display; 19 | using Serilog.Sinks.Xamarin; 20 | 21 | namespace Serilog 22 | { 23 | /// 24 | /// Adds WriteTo.AndroidLog() to the logger configuration. 25 | /// 26 | public static class LoggerConfigurationXamarinExtensions 27 | { 28 | const string DefaultAndroidLogOutputTemplate = "[{Level}] {Message:l{NewLine:l}{Exception:l}"; 29 | 30 | /// 31 | /// Write to the built-in Android log. 32 | /// 33 | /// The configuration this applies to. 34 | /// The minimum log event level required in order to write an event to the sink. 35 | /// Output template providing the format for events 36 | /// Supplies culture-specific formatting information, or null. 37 | /// Logger configuration, allowing configuration to continue. 38 | /// A required parameter is null. 39 | public static LoggerConfiguration AndroidLog(this LoggerSinkConfiguration sinkConfiguration, 40 | LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum, 41 | string outputTemplate = DefaultAndroidLogOutputTemplate, 42 | IFormatProvider formatProvider = null) 43 | { 44 | 45 | if (sinkConfiguration == null) 46 | throw new ArgumentNullException("sinkConfiguration"); 47 | 48 | if (outputTemplate == null) 49 | throw new ArgumentNullException("outputTemplate"); 50 | 51 | var formatter = new MessageTemplateTextFormatter(outputTemplate, formatProvider); 52 | return sinkConfiguration.Sink(new AndroidLogSink(formatter), restrictedToMinimumLevel); 53 | } 54 | } 55 | } -------------------------------------------------------------------------------- /src/Serilog.Sinks.Xamarin/Sinks/Xamarin/apple-common/LoggerConfigurationXamarinExtensions.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Serilog Contributors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using System; 16 | using Serilog.Configuration; 17 | using Serilog.Events; 18 | using Serilog.Formatting.Display; 19 | using Serilog.Sinks.Xamarin; 20 | 21 | namespace Serilog 22 | { 23 | /// 24 | /// Adds WriteTo.NSLog() to the logger configuration. 25 | /// 26 | public static class LoggerConfigurationXamarinExtensions 27 | { 28 | const string DefaultNSLogOutputTemplate = "[{Level}] {Message:l}{NewLine:l}{Exception:l}"; 29 | 30 | /// 31 | /// Adds a sink that writes log events to Apple Unified Logging. 32 | /// 33 | /// The configuration being modified. 34 | /// The minimum log event level required in order to write an event to the sink. 35 | /// Template for the output events 36 | /// Supplies culture-specific formatting information, or null. 37 | /// A required parameter is null. 38 | public static LoggerConfiguration NSLog(this LoggerSinkConfiguration sinkConfiguration, 39 | LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum, 40 | string outputTemplate = DefaultNSLogOutputTemplate, 41 | IFormatProvider formatProvider = null) { 42 | 43 | if (sinkConfiguration == null) 44 | throw new ArgumentNullException ("sinkConfiguration"); 45 | 46 | if (outputTemplate == null) 47 | throw new ArgumentNullException ("outputTemplate"); 48 | 49 | var formatter = new MessageTemplateTextFormatter (outputTemplate, formatProvider); 50 | return sinkConfiguration.Sink (new NSLogSink (formatter), restrictedToMinimumLevel); 51 | } 52 | } 53 | } 54 | 55 | -------------------------------------------------------------------------------- /src/Serilog.Sinks.Xamarin/Sinks/Xamarin/apple-common/NSLogSink.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2015 Serilog Contributors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using System; 16 | using System.IO; 17 | using Serilog.Core; 18 | using Serilog.Events; 19 | using Serilog.Formatting; 20 | 21 | namespace Serilog.Sinks.Xamarin 22 | { 23 | class NSLogSink : ILogEventSink 24 | { 25 | readonly ITextFormatter _textFormatter; 26 | 27 | public NSLogSink(ITextFormatter textFormatter) 28 | { 29 | if (textFormatter == null) throw new ArgumentNullException("textFormatter"); 30 | _textFormatter = textFormatter; 31 | } 32 | 33 | public void Emit(LogEvent logEvent) 34 | { 35 | if (logEvent == null) throw new ArgumentNullException("logEvent"); 36 | var renderSpace = new StringWriter(); 37 | _textFormatter.Format(logEvent, renderSpace); 38 | Console.WriteLine (renderSpace.ToString ()); 39 | } 40 | } 41 | } -------------------------------------------------------------------------------- /test/Blank.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serilog/serilog-sinks-xamarin/0beb06a55c5d0c91a3727f0b3de9c9c1e0c3b198/test/Blank.txt --------------------------------------------------------------------------------