├── .gitattributes
├── .github
├── FUNDING.yml
├── ISSUE_TEMPLATE
│ ├── bug_report.md
│ ├── custom.md
│ └── feature_request.md
└── workflows
│ └── build.yml
├── .gitignore
├── .travis.yml
├── CODE_OF_CONDUCT.md
├── LICENSE
├── README.md
├── SampleVideo.gif
├── assets
└── serilog-sink-nuget.png
└── src
├── Sample
├── CustomSimpleTextLog
│ ├── App.config
│ ├── CustomSimpleTextLog.csproj
│ ├── Form1.Designer.cs
│ ├── Form1.cs
│ ├── Form1.resx
│ ├── Program.cs
│ ├── Properties
│ │ ├── AssemblyInfo.cs
│ │ ├── Resources.Designer.cs
│ │ ├── Resources.resx
│ │ ├── Settings.Designer.cs
│ │ └── Settings.settings
│ └── packages.config
├── TestApplication
│ ├── App.config
│ ├── Form1.Designer.cs
│ ├── Form1.cs
│ ├── Form1.resx
│ ├── Form2.Designer.cs
│ ├── Form2.cs
│ ├── Form2.resx
│ ├── ILLink
│ │ └── ILLink.Descriptors.LibraryBuild.xml
│ ├── LogVieweer.Designer.cs
│ ├── LogVieweer.cs
│ ├── LogVieweer.resx
│ ├── MasterForm.Designer.cs
│ ├── MasterForm.cs
│ ├── MasterForm.resx
│ ├── Program.cs
│ ├── Properties
│ │ ├── AssemblyInfo.cs
│ │ ├── Resources.Designer.cs
│ │ ├── Resources.resx
│ │ ├── Settings.Designer.cs
│ │ └── Settings.settings
│ ├── RichTextBoxLogControlForm.Designer.cs
│ ├── RichTextBoxLogControlForm.cs
│ ├── RichTextBoxLogControlForm.resx
│ ├── TestApplication.csproj
│ └── packages.config
├── TestApplicationNet6
│ ├── Form1.Designer.cs
│ ├── Form1.cs
│ ├── Form1.resx
│ ├── Program.cs
│ └── TestApplicationNet9.csproj
└── TestApplicationWithTransparentBackground
│ ├── App.config
│ ├── Form1.Designer.cs
│ ├── Form1.cs
│ ├── Form1.resx
│ ├── Program.cs
│ ├── Properties
│ ├── AssemblyInfo.cs
│ ├── Resources.Designer.cs
│ ├── Resources.resx
│ ├── Settings.Designer.cs
│ └── Settings.settings
│ ├── TestApplicationWithTransparentBackground.csproj
│ └── packages.config
├── Serilog.Sinks.WinForms.Base
├── GridLogEvent.cs
├── Serilog.Sinks.WinForms.Base.csproj
├── WinFormsSinkInternal.cs
└── WindFromsSinkExtensions.cs
├── Serilog.Sinks.WinForms.Core
├── GridLog.Designer.cs
├── GridLog.cs
├── GridLog.resx
├── JsonLogTextBox.Designer.cs
├── JsonLogTextBox.cs
├── JsonLogTextBox.resx
├── RichTextBoxLogControl.Designer.cs
├── RichTextBoxLogControl.cs
├── SaveFileHelper.cs
├── Serilog.Sinks.WinForms.Core.csproj
├── SimpleLogTextBox.Designer.cs
├── SimpleLogTextBox.cs
├── SimpleLogTextBox.resx
├── TransparentSimpleLogTextBox.Designer.cs
├── TransparentSimpleLogTextBox.cs
└── TransparentSimpleLogTextBox.resx
├── Serilog.Sinks.WinForms.Net
├── App.config
├── GridLog.Designer.cs
├── GridLog.cs
├── GridLog.resx
├── ILLink
│ └── ILLink.Descriptors.LibraryBuild.xml
├── JsonLogTextBox.Designer.cs
├── JsonLogTextBox.cs
├── JsonLogTextBox.resx
├── Properties
│ └── AssemblyInfo.cs
├── RichTextBoxLogControl.Designer.cs
├── RichTextBoxLogControl.cs
├── SaveFileHelper.cs
├── Serilog.Sinks.WinForms.csproj
├── Serilog.Sinks.WinForms.nuspec
├── SimpleLogTextBox.Designer.cs
├── SimpleLogTextBox.cs
├── SimpleLogTextBox.resx
├── TransparentSimpleLogTextBox.Designer.cs
├── TransparentSimpleLogTextBox.cs
├── TransparentSimpleLogTextBox.resx
└── packages.config
├── Serilog.Sinks.WinForms.sln
└── release.ps1
/.gitattributes:
--------------------------------------------------------------------------------
1 | ###############################################################################
2 | # Set default behavior to automatically normalize line endings.
3 | ###############################################################################
4 | * text=auto
5 |
6 | ###############################################################################
7 | # Set default behavior for command prompt diff.
8 | #
9 | # This is need for earlier builds of msysgit that does not have it on by
10 | # default for csharp files.
11 | # Note: This is only used by command line
12 | ###############################################################################
13 | #*.cs diff=csharp
14 |
15 | ###############################################################################
16 | # Set the merge driver for project and solution files
17 | #
18 | # Merging from the command prompt will add diff markers to the files if there
19 | # are conflicts (Merging from VS is not affected by the settings below, in VS
20 | # the diff markers are never inserted). Diff markers may cause the following
21 | # file extensions to fail to load in VS. An alternative would be to treat
22 | # these files as binary and thus will always conflict and require user
23 | # intervention with every merge. To do so, just uncomment the entries below
24 | ###############################################################################
25 | #*.sln merge=binary
26 | #*.csproj merge=binary
27 | #*.vbproj merge=binary
28 | #*.vcxproj merge=binary
29 | #*.vcproj merge=binary
30 | #*.dbproj merge=binary
31 | #*.fsproj merge=binary
32 | #*.lsproj merge=binary
33 | #*.wixproj merge=binary
34 | #*.modelproj merge=binary
35 | #*.sqlproj merge=binary
36 | #*.wwaproj merge=binary
37 |
38 | ###############################################################################
39 | # behavior for image files
40 | #
41 | # image files are treated as binary by default.
42 | ###############################################################################
43 | #*.jpg binary
44 | #*.png binary
45 | #*.gif binary
46 |
47 | ###############################################################################
48 | # diff behavior for common document formats
49 | #
50 | # Convert binary document formats to text before diffing them. This feature
51 | # is only available from the command line. Turn it on by uncommenting the
52 | # entries below.
53 | ###############################################################################
54 | #*.doc diff=astextplain
55 | #*.DOC diff=astextplain
56 | #*.docx diff=astextplain
57 | #*.DOCX diff=astextplain
58 | #*.dot diff=astextplain
59 | #*.DOT diff=astextplain
60 | #*.pdf diff=astextplain
61 | #*.PDF diff=astextplain
62 | #*.rtf diff=astextplain
63 | #*.RTF diff=astextplain
64 |
--------------------------------------------------------------------------------
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | # These are supported funding model platforms
2 |
3 | github: [] # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
4 | patreon: # Replace with a single Patreon username
5 | open_collective: # Replace with a single Open Collective username
6 | ko_fi: # Replace with a single Ko-fi username
7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
9 | liberapay: # Replace with a single Liberapay username
10 | issuehunt: # Replace with a single IssueHunt username
11 | otechie: # Replace with a single Otechie username
12 | lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry
13 | custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
14 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/bug_report.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Bug report
3 | about: Create a report to help us improve
4 | title: ''
5 | labels: ''
6 | assignees: ''
7 |
8 | ---
9 |
10 | **Describe the bug**
11 | A clear and concise description of what the bug is.
12 |
13 | **To Reproduce**
14 | Steps to reproduce the behavior:
15 | 1. Go to '...'
16 | 2. Click on '....'
17 | 3. Scroll down to '....'
18 | 4. See error
19 |
20 | **Expected behavior**
21 | A clear and concise description of what you expected to happen.
22 |
23 | **Screenshots**
24 | If applicable, add screenshots to help explain your problem.
25 |
26 | **Desktop (please complete the following information):**
27 | - OS: [e.g. iOS]
28 | - Browser [e.g. chrome, safari]
29 | - Version [e.g. 22]
30 |
31 | **Smartphone (please complete the following information):**
32 | - Device: [e.g. iPhone6]
33 | - OS: [e.g. iOS8.1]
34 | - Browser [e.g. stock browser, safari]
35 | - Version [e.g. 22]
36 |
37 | **Additional context**
38 | Add any other context about the problem here.
39 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/custom.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Custom issue template
3 | about: Describe this issue template's purpose here.
4 | title: ''
5 | labels: ''
6 | assignees: ''
7 |
8 | ---
9 |
10 |
11 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/feature_request.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Feature request
3 | about: Suggest an idea for this project
4 | title: ''
5 | labels: ''
6 | assignees: ''
7 |
8 | ---
9 |
10 | **Is your feature request related to a problem? Please describe.**
11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
12 |
13 | **Describe the solution you'd like**
14 | A clear and concise description of what you want to happen.
15 |
16 | **Describe alternatives you've considered**
17 | A clear and concise description of any alternative solutions or features you've considered.
18 |
19 | **Additional context**
20 | Add any other context or screenshots about the feature request here.
21 |
--------------------------------------------------------------------------------
/.github/workflows/build.yml:
--------------------------------------------------------------------------------
1 | name: Build and Publish
2 |
3 | on:
4 | release:
5 | types: [published]
6 |
7 | jobs:
8 |
9 | build:
10 | runs-on: windows-latest
11 |
12 | env:
13 | Solution_Name: Serilog.Sinks.WinForms.sln
14 | steps:
15 | - uses: actions/checkout@v2
16 | - name: Setup Nuget.exe
17 | uses: NuGet/setup-nuget@v1.0.5
18 | - name: Restore packages
19 | run: nuget restore src/Serilog.Sinks.WinForms.sln
20 | - name: Setup MSBuild.exe
21 | uses: microsoft/setup-msbuild@v1
22 | - name: Build with MSBuild
23 | run: msbuild src/Serilog.Sinks.WinForms.sln -p:Configuration=Release
24 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: csharp
2 | solution: src/Serilog.Sinks.WinForms.sln
3 |
--------------------------------------------------------------------------------
/CODE_OF_CONDUCT.md:
--------------------------------------------------------------------------------
1 | # Contributor Covenant Code of Conduct
2 |
3 | ## Our Pledge
4 |
5 | In the interest of fostering an open and welcoming environment, we as
6 | contributors and maintainers pledge to making participation in our project and
7 | our community a harassment-free experience for everyone, regardless of age, body
8 | size, disability, ethnicity, sex characteristics, gender identity and expression,
9 | level of experience, education, socio-economic status, nationality, personal
10 | appearance, race, religion, or sexual identity and orientation.
11 |
12 | ## Our Standards
13 |
14 | Examples of behavior that contributes to creating a positive environment
15 | include:
16 |
17 | * Using welcoming and inclusive language
18 | * Being respectful of differing viewpoints and experiences
19 | * Gracefully accepting constructive criticism
20 | * Focusing on what is best for the community
21 | * Showing empathy towards other community members
22 |
23 | Examples of unacceptable behavior by participants include:
24 |
25 | * The use of sexualized language or imagery and unwelcome sexual attention or
26 | advances
27 | * Trolling, insulting/derogatory comments, and personal or political attacks
28 | * Public or private harassment
29 | * Publishing others' private information, such as a physical or electronic
30 | address, without explicit permission
31 | * Other conduct which could reasonably be considered inappropriate in a
32 | professional setting
33 |
34 | ## Our Responsibilities
35 |
36 | Project maintainers are responsible for clarifying the standards of acceptable
37 | behavior and are expected to take appropriate and fair corrective action in
38 | response to any instances of unacceptable behavior.
39 |
40 | Project maintainers have the right and responsibility to remove, edit, or
41 | reject comments, commits, code, wiki edits, issues, and other contributions
42 | that are not aligned to this Code of Conduct, or to ban temporarily or
43 | permanently any contributor for other behaviors that they deem inappropriate,
44 | threatening, offensive, or harmful.
45 |
46 | ## Scope
47 |
48 | This Code of Conduct applies both within project spaces and in public spaces
49 | when an individual is representing the project or its community. Examples of
50 | representing a project or community include using an official project e-mail
51 | address, posting via an official social media account, or acting as an appointed
52 | representative at an online or offline event. Representation of a project may be
53 | further defined and clarified by project maintainers.
54 |
55 | ## Enforcement
56 |
57 | Instances of abusive, harassing, or otherwise unacceptable behavior may be
58 | reported by contacting the project team at naqvi.umair@gmail.com. All
59 | complaints will be reviewed and investigated and will result in a response that
60 | is deemed necessary and appropriate to the circumstances. The project team is
61 | obligated to maintain confidentiality with regard to the reporter of an incident.
62 | Further details of specific enforcement policies may be posted separately.
63 |
64 | Project maintainers who do not follow or enforce the Code of Conduct in good
65 | faith may face temporary or permanent repercussions as determined by other
66 | members of the project's leadership.
67 |
68 | ## Attribution
69 |
70 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71 | available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
72 |
73 | [homepage]: https://www.contributor-covenant.org
74 |
75 | For answers to common questions about this code of conduct, see
76 | https://www.contributor-covenant.org/faq
77 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2020 Umair Syed
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | [](https://www.buymeacoffee.com/umairsyed613)
2 |
3 | ## Build Status
4 |
5 | 
6 |
7 | # Serilog.Sinks.WinForms (.net framework >= 4.6)
8 |
9 | [](https://badge.fury.io/nu/Serilog.Sinks.WinForms) [](https://www.nuget.org/packages/Serilog.Sinks.WinForms)
10 |
11 | # Serilog.Sinks.WinForms.Core (.net 6-8-9)
12 |
13 | [](https://badge.fury.io/nu/Serilog.Sinks.WinForms.Core) [](https://www.nuget.org/packages/Serilog.Sinks.WinForms.Core)
14 |
15 |
16 | Writes [Serilog](https://serilog.net) events to Windows Froms Application TextBox or Datagridview control from anywhere in your application.
17 |
18 | ### Getting started
19 |
20 | Install the [Serilog.Sinks.WinForms](https://www.nuget.org/packages/Serilog.Sinks.WinForms/) package from NuGet:
21 |
22 | ```powershell
23 | Install-Package Serilog.Sinks.WinForms
24 | ```
25 |
26 | Install the [Serilog.Sinks.WinForms.Core](https://www.nuget.org/packages/Serilog.Sinks.WinForms.Core/) package from NuGet:
27 |
28 | ```powershell
29 | Install-Package Serilog.Sinks.WinForms.Core
30 | ```
31 |
32 | To configure the sink in C# code, call `WriteToSimpleAndRichTextBox()` or `WriteToJsonTextBox()` or `WriteToGridView()` during logger configuration:
33 |
34 | ##### Simple Text Formatted Log And Rich TextBox Log Control
35 |
36 | SimpleLogTextBox or RichTextBoxLogControl can be used from visual studio toolbox once the package is added to the project.
37 |
38 | ```csharp
39 | Log.Logger = new LoggerConfiguration()
40 | .WriteToSimpleAndRichTextBox()
41 | .CreateLogger();
42 | ```
43 |
44 | SimpleLogTextBox or RichTextBoxLogControl with custom Configuration. SimpleLogTextBox accepts [ITextFormatter](https://github.com/serilog/serilog/blob/dev/src/Serilog/Formatting/ITextFormatter.cs)
45 |
46 | ```csharp
47 | Log.Logger = new LoggerConfiguration()
48 | .WriteToSimpleAndRichTextBox(new MessageTemplateTextFormatter("{Timestamp} [{Level}] {Message} {Exception}"))
49 | .CreateLogger();
50 | ```
51 |
52 | ##### Json Formatted Log
53 |
54 | JsonLogTextBox can be used from visual studio toolbox once the package is added to the project.
55 |
56 | ```csharp
57 | Log.Logger = new LoggerConfiguration()
58 | .WriteToJsonTextBox()
59 | .CreateLogger();
60 | ```
61 |
62 | JsonLogTextBox with custom Configuration. JsonLogTextBox accepts [ITextFormatter](https://github.com/serilog/serilog/blob/dev/src/Serilog/Formatting/ITextFormatter.cs)
63 |
64 | ```csharp
65 | Log.Logger = new LoggerConfiguration()
66 | .WriteToJsonTextBox(new JsonFormatter())
67 | .CreateLogger();
68 | ```
69 |
70 | ##### Datagridview Log
71 |
72 | GridLog can be used from visual studio toolbox once the package is added to the project.
73 |
74 | ```csharp
75 | Log.Logger = new LoggerConfiguration()
76 | .WriteToGridView()
77 | .CreateLogger();
78 | ```
79 |
80 | #### Log For Context
81 |
82 | SimpleLogTextBox, RichTextBoxLogControl or JsonLogTextBox can be configured to display log for specific ***Context***.
83 | All of the controls have property **For Context** which can be configured with ***namespace.classname*** for example ***TestApplication.Form2*** you can find the sample here >> [Sample](https://github.com/umairsyed613/Serilog.Sinks.WinForms/blob/master/src/Sample/TestApplication/Form2.cs)
84 |
85 | **Note:** Remember to configure Logger instance with ***Enrich.FromLogContext()***
86 |
87 |
88 | #### Save and Clear Logs
89 | SimpleLogTextBox, RichTextBoxLogControl or JsonLogTextBox have two method available for saving log to file or clear the log from the log control.
90 | ***ClearLogs()*** AND ***SaveLogToFile()***
91 |
92 | Check the usage in sample application here [Sample](https://github.com/umairsyed613/Serilog.Sinks.WinForms/blob/master/src/Sample/TestApplication/Form2.cs)
93 |
94 |
95 | ### Sample Code
96 |
97 | Find the sample running application [here](https://github.com/umairsyed613/Serilog.Sinks.WinForms/tree/master/Sample/TestApplication/)
98 |
99 | 
100 |
--------------------------------------------------------------------------------
/SampleVideo.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/umairsyed613/Serilog.Sinks.WinForms/8de7b98c96a7a39d674b26a2c07ca2678bc0ccac/SampleVideo.gif
--------------------------------------------------------------------------------
/assets/serilog-sink-nuget.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/umairsyed613/Serilog.Sinks.WinForms/8de7b98c96a7a39d674b26a2c07ca2678bc0ccac/assets/serilog-sink-nuget.png
--------------------------------------------------------------------------------
/src/Sample/CustomSimpleTextLog/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/src/Sample/CustomSimpleTextLog/Form1.Designer.cs:
--------------------------------------------------------------------------------
1 |
2 | namespace CustomSimpleTextLog
3 | {
4 | partial class Form1
5 | {
6 | ///
7 | /// Required designer variable.
8 | ///
9 | private System.ComponentModel.IContainer components = null;
10 |
11 | ///
12 | /// Clean up any resources being used.
13 | ///
14 | /// true if managed resources should be disposed; otherwise, false.
15 | protected override void Dispose(bool disposing)
16 | {
17 | if (disposing && (components != null))
18 | {
19 | components.Dispose();
20 | }
21 | base.Dispose(disposing);
22 | }
23 |
24 | #region Windows Form Designer generated code
25 |
26 | ///
27 | /// Required method for Designer support - do not modify
28 | /// the contents of this method with the code editor.
29 | ///
30 | private void InitializeComponent()
31 | {
32 | this.richTextBox1 = new System.Windows.Forms.RichTextBox();
33 | this.textBox1 = new System.Windows.Forms.TextBox();
34 | this.label1 = new System.Windows.Forms.Label();
35 | this.label2 = new System.Windows.Forms.Label();
36 | this.textBox2 = new System.Windows.Forms.TextBox();
37 | this.button1 = new System.Windows.Forms.Button();
38 | this.SuspendLayout();
39 | //
40 | // richTextBox1
41 | //
42 | this.richTextBox1.Location = new System.Drawing.Point(12, 86);
43 | this.richTextBox1.Name = "richTextBox1";
44 | this.richTextBox1.Size = new System.Drawing.Size(776, 176);
45 | this.richTextBox1.TabIndex = 0;
46 | this.richTextBox1.Text = "";
47 | //
48 | // textBox1
49 | //
50 | this.textBox1.Location = new System.Drawing.Point(13, 301);
51 | this.textBox1.Multiline = true;
52 | this.textBox1.Name = "textBox1";
53 | this.textBox1.Size = new System.Drawing.Size(775, 137);
54 | this.textBox1.TabIndex = 1;
55 | //
56 | // label1
57 | //
58 | this.label1.AutoSize = true;
59 | this.label1.Location = new System.Drawing.Point(12, 285);
60 | this.label1.Name = "label1";
61 | this.label1.Size = new System.Drawing.Size(45, 13);
62 | this.label1.TabIndex = 2;
63 | this.label1.Text = "Textbox";
64 | //
65 | // label2
66 | //
67 | this.label2.AutoSize = true;
68 | this.label2.Location = new System.Drawing.Point(12, 70);
69 | this.label2.Name = "label2";
70 | this.label2.Size = new System.Drawing.Size(67, 13);
71 | this.label2.TabIndex = 3;
72 | this.label2.Text = "RichTextbox";
73 | //
74 | // textBox2
75 | //
76 | this.textBox2.Location = new System.Drawing.Point(15, 25);
77 | this.textBox2.Name = "textBox2";
78 | this.textBox2.Size = new System.Drawing.Size(533, 20);
79 | this.textBox2.TabIndex = 4;
80 | this.textBox2.Text = "Write to Log";
81 | //
82 | // button1
83 | //
84 | this.button1.Location = new System.Drawing.Point(554, 23);
85 | this.button1.Name = "button1";
86 | this.button1.Size = new System.Drawing.Size(75, 23);
87 | this.button1.TabIndex = 5;
88 | this.button1.Text = "Write";
89 | this.button1.UseVisualStyleBackColor = true;
90 | this.button1.Click += new System.EventHandler(this.button1_Click);
91 | //
92 | // Form1
93 | //
94 | this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
95 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
96 | this.ClientSize = new System.Drawing.Size(800, 450);
97 | this.Controls.Add(this.button1);
98 | this.Controls.Add(this.textBox2);
99 | this.Controls.Add(this.label2);
100 | this.Controls.Add(this.label1);
101 | this.Controls.Add(this.textBox1);
102 | this.Controls.Add(this.richTextBox1);
103 | this.Name = "Form1";
104 | this.Text = "Form1";
105 | this.Load += new System.EventHandler(this.Form1_Load);
106 | this.ResumeLayout(false);
107 | this.PerformLayout();
108 |
109 | }
110 |
111 | #endregion
112 |
113 | private System.Windows.Forms.RichTextBox richTextBox1;
114 | private System.Windows.Forms.TextBox textBox1;
115 | private System.Windows.Forms.Label label1;
116 | private System.Windows.Forms.Label label2;
117 | private System.Windows.Forms.TextBox textBox2;
118 | private System.Windows.Forms.Button button1;
119 | }
120 | }
121 |
122 |
--------------------------------------------------------------------------------
/src/Sample/CustomSimpleTextLog/Form1.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Windows.Forms;
3 | using Serilog;
4 | using Serilog.Sinks.WinForms.Base;
5 |
6 | namespace CustomSimpleTextLog
7 | {
8 | public partial class Form1 : Form
9 | {
10 | public Form1()
11 | {
12 | InitializeComponent();
13 | }
14 |
15 | private void Form1_Load(object sender, EventArgs e)
16 | {
17 | WindFormsSink.SimpleTextBoxSink.OnLogReceived += SimpleTextBoxSinkOnOnLogReceived;
18 | }
19 |
20 | private void SimpleTextBoxSinkOnOnLogReceived(string context, string str)
21 | {
22 | this.textBox1.AppendText(str);
23 | this.richTextBox1.AppendText(str);
24 | }
25 |
26 | private void button1_Click(object sender, EventArgs e)
27 | {
28 | Log.Information(textBox2.Text);
29 | }
30 | }
31 | }
--------------------------------------------------------------------------------
/src/Sample/CustomSimpleTextLog/Form1.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 | text/microsoft-resx
110 |
111 |
112 | 2.0
113 |
114 |
115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
119 |
120 |
--------------------------------------------------------------------------------
/src/Sample/CustomSimpleTextLog/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Windows.Forms;
3 | using Serilog;
4 | using Serilog.Sinks.WinForms.Base;
5 |
6 | namespace CustomSimpleTextLog
7 | {
8 | static class Program
9 | {
10 | ///
11 | /// The main entry point for the application.
12 | ///
13 | [STAThread]
14 | static void Main()
15 | {
16 | Log.Logger = new LoggerConfiguration()
17 | .WriteToSimpleAndRichTextBox()
18 | .CreateLogger();
19 |
20 | Application.EnableVisualStyles();
21 | Application.SetCompatibleTextRenderingDefault(false);
22 | Application.Run(new Form1());
23 | }
24 | }
25 | }
--------------------------------------------------------------------------------
/src/Sample/CustomSimpleTextLog/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("CustomSimpleTextLog")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("CustomSimpleTextLog")]
13 | [assembly: AssemblyCopyright("Copyright © 2021")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("151559cf-e59e-4cc1-8cdb-ff56882f9035")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/src/Sample/CustomSimpleTextLog/Properties/Resources.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.42000
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 |
12 | namespace CustomSimpleTextLog.Properties
13 | {
14 | ///
15 | /// A strongly-typed resource class, for looking up localized strings, etc.
16 | ///
17 | // This class was auto-generated by the StronglyTypedResourceBuilder
18 | // class via a tool like ResGen or Visual Studio.
19 | // To add or remove a member, edit your .ResX file then rerun ResGen
20 | // with the /str option, or rebuild your VS project.
21 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
22 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
23 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
24 | internal class Resources
25 | {
26 |
27 | private static global::System.Resources.ResourceManager resourceMan;
28 |
29 | private static global::System.Globalization.CultureInfo resourceCulture;
30 |
31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
32 | internal Resources()
33 | {
34 | }
35 |
36 | ///
37 | /// Returns the cached ResourceManager instance used by this class.
38 | ///
39 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
40 | internal static global::System.Resources.ResourceManager ResourceManager
41 | {
42 | get
43 | {
44 | if ((resourceMan == null))
45 | {
46 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("CustomSimpleTextLog.Properties.Resources", typeof(Resources).Assembly);
47 | resourceMan = temp;
48 | }
49 | return resourceMan;
50 | }
51 | }
52 |
53 | ///
54 | /// Overrides the current thread's CurrentUICulture property for all
55 | /// resource lookups using this strongly typed resource class.
56 | ///
57 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
58 | internal static global::System.Globalization.CultureInfo Culture
59 | {
60 | get
61 | {
62 | return resourceCulture;
63 | }
64 | set
65 | {
66 | resourceCulture = value;
67 | }
68 | }
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/src/Sample/CustomSimpleTextLog/Properties/Resources.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 | text/microsoft-resx
107 |
108 |
109 | 2.0
110 |
111 |
112 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
113 |
114 |
115 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
--------------------------------------------------------------------------------
/src/Sample/CustomSimpleTextLog/Properties/Settings.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.42000
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 |
12 | namespace CustomSimpleTextLog.Properties
13 | {
14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase
17 | {
18 |
19 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
20 |
21 | public static Settings Default
22 | {
23 | get
24 | {
25 | return defaultInstance;
26 | }
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/Sample/CustomSimpleTextLog/Properties/Settings.settings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/src/Sample/CustomSimpleTextLog/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/src/Sample/TestApplication/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/src/Sample/TestApplication/Form1.Designer.cs:
--------------------------------------------------------------------------------
1 | namespace TestApplication
2 | {
3 | partial class Form1
4 | {
5 | ///
6 | /// Required designer variable.
7 | ///
8 | private System.ComponentModel.IContainer components = null;
9 |
10 | ///
11 | /// Clean up any resources being used.
12 | ///
13 | /// true if managed resources should be disposed; otherwise, false.
14 | protected override void Dispose(bool disposing)
15 | {
16 | if (disposing && (components != null))
17 | {
18 | components.Dispose();
19 | }
20 | base.Dispose(disposing);
21 | }
22 |
23 | #region Windows Form Designer generated code
24 |
25 | ///
26 | /// Required method for Designer support - do not modify
27 | /// the contents of this method with the code editor.
28 | ///
29 | private void InitializeComponent()
30 | {
31 | this.button1 = new System.Windows.Forms.Button();
32 | this.textBox1 = new System.Windows.Forms.TextBox();
33 | this.SuspendLayout();
34 | //
35 | // button1
36 | //
37 | this.button1.Location = new System.Drawing.Point(474, 29);
38 | this.button1.Name = "button1";
39 | this.button1.Size = new System.Drawing.Size(75, 23);
40 | this.button1.TabIndex = 2;
41 | this.button1.Text = "Add Log";
42 | this.button1.UseVisualStyleBackColor = true;
43 | this.button1.Click += new System.EventHandler(this.button1_Click);
44 | //
45 | // textBox1
46 | //
47 | this.textBox1.Location = new System.Drawing.Point(15, 31);
48 | this.textBox1.Name = "textBox1";
49 | this.textBox1.Size = new System.Drawing.Size(453, 20);
50 | this.textBox1.TabIndex = 1;
51 | //
52 | // Form1
53 | //
54 | this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
55 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
56 | this.ClientSize = new System.Drawing.Size(561, 97);
57 | this.Controls.Add(this.textBox1);
58 | this.Controls.Add(this.button1);
59 | this.Name = "Form1";
60 | this.Text = "Simple Form1";
61 | this.ResumeLayout(false);
62 | this.PerformLayout();
63 |
64 | }
65 |
66 | #endregion
67 | private System.Windows.Forms.Button button1;
68 | private System.Windows.Forms.TextBox textBox1;
69 | }
70 | }
71 |
72 |
--------------------------------------------------------------------------------
/src/Sample/TestApplication/Form1.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.ComponentModel;
4 | using System.Data;
5 | using System.Drawing;
6 | using System.Linq;
7 | using System.Text;
8 | using System.Threading.Tasks;
9 | using System.Windows.Forms;
10 |
11 | using Serilog;
12 |
13 | namespace TestApplication
14 | {
15 | public partial class Form1 : Form
16 | {
17 | private ILogger logger = Log.ForContext();
18 | public Form1()
19 | {
20 | InitializeComponent();
21 | logger.Information("Form1 has been Initialized");
22 | }
23 |
24 | private void button1_Click(object sender, EventArgs e)
25 | {
26 | logger.Information(textBox1.Text);
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/Sample/TestApplication/Form1.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 | text/microsoft-resx
110 |
111 |
112 | 2.0
113 |
114 |
115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
119 |
120 |
--------------------------------------------------------------------------------
/src/Sample/TestApplication/Form2.Designer.cs:
--------------------------------------------------------------------------------
1 | namespace TestApplication
2 | {
3 | partial class Form2
4 | {
5 | ///
6 | /// Required designer variable.
7 | ///
8 | private System.ComponentModel.IContainer components = null;
9 |
10 | ///
11 | /// Clean up any resources being used.
12 | ///
13 | /// true if managed resources should be disposed; otherwise, false.
14 | protected override void Dispose(bool disposing)
15 | {
16 | if (disposing && (components != null))
17 | {
18 | components.Dispose();
19 | }
20 | base.Dispose(disposing);
21 | }
22 |
23 | #region Windows Form Designer generated code
24 |
25 | ///
26 | /// Required method for Designer support - do not modify
27 | /// the contents of this method with the code editor.
28 | ///
29 | private void InitializeComponent()
30 | {
31 | this.textBox1 = new System.Windows.Forms.TextBox();
32 | this.button1 = new System.Windows.Forms.Button();
33 | this.button2 = new System.Windows.Forms.Button();
34 | this.button3 = new System.Windows.Forms.Button();
35 | this.simpleLogTextBox1 = new Serilog.Sinks.WinForms.SimpleLogTextBox();
36 | this.button4 = new System.Windows.Forms.Button();
37 | this.SuspendLayout();
38 | //
39 | // textBox1
40 | //
41 | this.textBox1.Location = new System.Drawing.Point(39, 29);
42 | this.textBox1.Name = "textBox1";
43 | this.textBox1.Size = new System.Drawing.Size(405, 20);
44 | this.textBox1.TabIndex = 0;
45 | //
46 | // button1
47 | //
48 | this.button1.Location = new System.Drawing.Point(462, 28);
49 | this.button1.Name = "button1";
50 | this.button1.Size = new System.Drawing.Size(99, 23);
51 | this.button1.TabIndex = 1;
52 | this.button1.Text = "Write To Log";
53 | this.button1.UseVisualStyleBackColor = true;
54 | this.button1.Click += new System.EventHandler(this.button1_Click);
55 | //
56 | // button2
57 | //
58 | this.button2.Location = new System.Drawing.Point(462, 57);
59 | this.button2.Name = "button2";
60 | this.button2.Size = new System.Drawing.Size(99, 23);
61 | this.button2.TabIndex = 2;
62 | this.button2.Text = "Throw Error";
63 | this.button2.UseVisualStyleBackColor = true;
64 | this.button2.Click += new System.EventHandler(this.button2_Click);
65 | //
66 | // button3
67 | //
68 | this.button3.Location = new System.Drawing.Point(345, 57);
69 | this.button3.Name = "button3";
70 | this.button3.Size = new System.Drawing.Size(99, 23);
71 | this.button3.TabIndex = 4;
72 | this.button3.Text = "Clear Logs";
73 | this.button3.UseVisualStyleBackColor = true;
74 | this.button3.Click += new System.EventHandler(this.button3_Click);
75 | //
76 | // simpleLogTextBox1
77 | //
78 | this.simpleLogTextBox1.ForContext = "TestApplication.Form2";
79 | this.simpleLogTextBox1.Location = new System.Drawing.Point(39, 93);
80 | this.simpleLogTextBox1.LogBorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
81 | this.simpleLogTextBox1.LogPadding = new System.Windows.Forms.Padding(3);
82 | this.simpleLogTextBox1.Name = "simpleLogTextBox1";
83 | this.simpleLogTextBox1.ReadOnly = false;
84 | this.simpleLogTextBox1.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
85 | this.simpleLogTextBox1.Size = new System.Drawing.Size(522, 271);
86 | this.simpleLogTextBox1.TabIndex = 3;
87 | //
88 | // button4
89 | //
90 | this.button4.Location = new System.Drawing.Point(240, 57);
91 | this.button4.Name = "button4";
92 | this.button4.Size = new System.Drawing.Size(99, 23);
93 | this.button4.TabIndex = 5;
94 | this.button4.Text = "Save Logs";
95 | this.button4.UseVisualStyleBackColor = true;
96 | this.button4.Click += new System.EventHandler(this.button4_Click);
97 | //
98 | // Form2
99 | //
100 | this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
101 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
102 | this.ClientSize = new System.Drawing.Size(581, 376);
103 | this.Controls.Add(this.button4);
104 | this.Controls.Add(this.button3);
105 | this.Controls.Add(this.simpleLogTextBox1);
106 | this.Controls.Add(this.button2);
107 | this.Controls.Add(this.button1);
108 | this.Controls.Add(this.textBox1);
109 | this.Name = "Form2";
110 | this.Text = "Sample Form2";
111 | this.ResumeLayout(false);
112 | this.PerformLayout();
113 |
114 | }
115 |
116 | #endregion
117 |
118 | private System.Windows.Forms.TextBox textBox1;
119 | private System.Windows.Forms.Button button1;
120 | private System.Windows.Forms.Button button2;
121 | private Serilog.Sinks.WinForms.SimpleLogTextBox simpleLogTextBox1;
122 | private System.Windows.Forms.Button button3;
123 | private System.Windows.Forms.Button button4;
124 | }
125 | }
--------------------------------------------------------------------------------
/src/Sample/TestApplication/Form2.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.ComponentModel;
4 | using System.Data;
5 | using System.Drawing;
6 | using System.Linq;
7 | using System.Text;
8 | using System.Threading.Tasks;
9 | using System.Windows.Forms;
10 |
11 | using Serilog;
12 |
13 | namespace TestApplication
14 | {
15 | public partial class Form2 : Form
16 | {
17 | private static readonly ILogger _logger = Log.ForContext();
18 |
19 | public Form2()
20 | {
21 | InitializeComponent();
22 | Log.Information("Form2 has been Initialized");
23 | }
24 |
25 | private void button1_Click(object sender, EventArgs e)
26 | {
27 | _logger.Information(textBox1.Text);
28 | }
29 |
30 | private void button2_Click(object sender, EventArgs e)
31 | {
32 | try
33 | {
34 | throw new Exception("Throwing exception from Form2");
35 | }
36 | catch (Exception exception)
37 | {
38 | _logger.Error(exception, "Error Happened in Form2");
39 | }
40 | }
41 |
42 | private void button3_Click(object sender, EventArgs e)
43 | {
44 | simpleLogTextBox1.ClearLogs();
45 | }
46 |
47 | private void button4_Click(object sender, EventArgs e)
48 | {
49 | simpleLogTextBox1.SaveLogToFile();
50 | }
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/src/Sample/TestApplication/Form2.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 | text/microsoft-resx
110 |
111 |
112 | 2.0
113 |
114 |
115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
119 |
120 |
--------------------------------------------------------------------------------
/src/Sample/TestApplication/ILLink/ILLink.Descriptors.LibraryBuild.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/src/Sample/TestApplication/LogVieweer.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.ComponentModel;
4 | using System.Data;
5 | using System.Drawing;
6 | using System.Linq;
7 | using System.Text;
8 | using System.Threading.Tasks;
9 | using System.Windows.Forms;
10 |
11 | namespace TestApplication
12 | {
13 | public partial class LogVieweer : Form
14 | {
15 | public LogVieweer()
16 | {
17 | InitializeComponent();
18 | }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/src/Sample/TestApplication/LogVieweer.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 | text/microsoft-resx
110 |
111 |
112 | 2.0
113 |
114 |
115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
119 |
120 |
--------------------------------------------------------------------------------
/src/Sample/TestApplication/MasterForm.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.ComponentModel;
4 | using System.Data;
5 | using System.Drawing;
6 | using System.Drawing.Text;
7 | using System.Linq;
8 | using System.Text;
9 | using System.Threading.Tasks;
10 | using System.Windows.Forms;
11 |
12 | namespace TestApplication
13 | {
14 | public partial class MasterForm : Form
15 | {
16 | public MasterForm()
17 | {
18 | InitializeComponent();
19 | }
20 |
21 | private void toolStripButton1_Click(object sender, EventArgs e)
22 | {
23 | var form1 = new Form1();
24 | form1.MdiParent = this;
25 | form1.Show();
26 | }
27 |
28 | private void toolStripButton2_Click(object sender, EventArgs e)
29 | {
30 | var form2 = new Form2();
31 | form2.MdiParent = this;
32 | form2.Show();
33 | }
34 |
35 | private void toolStripButton3_Click(object sender, EventArgs e)
36 | {
37 | var LogViewer = new LogVieweer
38 | {
39 | MdiParent = this
40 | };
41 | LogViewer.Show();
42 | }
43 |
44 | private void toolStripButton4_Click(object sender, EventArgs e)
45 | {
46 | var r = new RichTextBoxLogControlForm();
47 | r.MdiParent = this;
48 | r.Show();
49 | }
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/src/Sample/TestApplication/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Windows.Forms;
3 |
4 | using Serilog;
5 | using Serilog.Sinks.WinForms.Base;
6 |
7 | namespace TestApplication
8 | {
9 | static class Program
10 | {
11 | ///
12 | /// The main entry point for the application.
13 | ///
14 | [STAThread]
15 | static void Main()
16 | {
17 | ConfigureSerilog();
18 | Application.EnableVisualStyles();
19 | Application.SetCompatibleTextRenderingDefault(false);
20 | Application.Run(new MasterForm());
21 | }
22 |
23 | private static void ConfigureSerilog()
24 | {
25 | Log.Logger = new LoggerConfiguration()
26 | .Enrich.FromLogContext()
27 | .WriteToGridView()
28 | .WriteToJsonTextBox()
29 | .WriteToSimpleAndRichTextBox()
30 | .CreateLogger();
31 | }
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/src/Sample/TestApplication/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("TestApplication")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("TestApplication")]
13 | [assembly: AssemblyCopyright("Copyright © 2020")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("9128af8c-2e4b-486e-aef2-f48de2f61b09")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/src/Sample/TestApplication/Properties/Resources.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.42000
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace TestApplication.Properties
12 | {
13 |
14 |
15 | ///
16 | /// A strongly-typed resource class, for looking up localized strings, etc.
17 | ///
18 | // This class was auto-generated by the StronglyTypedResourceBuilder
19 | // class via a tool like ResGen or Visual Studio.
20 | // To add or remove a member, edit your .ResX file then rerun ResGen
21 | // with the /str option, or rebuild your VS project.
22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
25 | internal class Resources
26 | {
27 |
28 | private static global::System.Resources.ResourceManager resourceMan;
29 |
30 | private static global::System.Globalization.CultureInfo resourceCulture;
31 |
32 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
33 | internal Resources()
34 | {
35 | }
36 |
37 | ///
38 | /// Returns the cached ResourceManager instance used by this class.
39 | ///
40 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
41 | internal static global::System.Resources.ResourceManager ResourceManager
42 | {
43 | get
44 | {
45 | if ((resourceMan == null))
46 | {
47 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("TestApplication.Properties.Resources", typeof(Resources).Assembly);
48 | resourceMan = temp;
49 | }
50 | return resourceMan;
51 | }
52 | }
53 |
54 | ///
55 | /// Overrides the current thread's CurrentUICulture property for all
56 | /// resource lookups using this strongly typed resource class.
57 | ///
58 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
59 | internal static global::System.Globalization.CultureInfo Culture
60 | {
61 | get
62 | {
63 | return resourceCulture;
64 | }
65 | set
66 | {
67 | resourceCulture = value;
68 | }
69 | }
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/src/Sample/TestApplication/Properties/Resources.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 | text/microsoft-resx
107 |
108 |
109 | 2.0
110 |
111 |
112 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
113 |
114 |
115 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
--------------------------------------------------------------------------------
/src/Sample/TestApplication/Properties/Settings.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.42000
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace TestApplication.Properties
12 | {
13 |
14 |
15 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
16 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
17 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase
18 | {
19 |
20 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
21 |
22 | public static Settings Default
23 | {
24 | get
25 | {
26 | return defaultInstance;
27 | }
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/src/Sample/TestApplication/Properties/Settings.settings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/src/Sample/TestApplication/RichTextBoxLogControlForm.Designer.cs:
--------------------------------------------------------------------------------
1 |
2 | namespace TestApplication
3 | {
4 | partial class RichTextBoxLogControlForm
5 | {
6 | ///
7 | /// Required designer variable.
8 | ///
9 | private System.ComponentModel.IContainer components = null;
10 |
11 | ///
12 | /// Clean up any resources being used.
13 | ///
14 | /// true if managed resources should be disposed; otherwise, false.
15 | protected override void Dispose(bool disposing)
16 | {
17 | if (disposing && (components != null))
18 | {
19 | components.Dispose();
20 | }
21 | base.Dispose(disposing);
22 | }
23 |
24 | #region Windows Form Designer generated code
25 |
26 | ///
27 | /// Required method for Designer support - do not modify
28 | /// the contents of this method with the code editor.
29 | ///
30 | private void InitializeComponent()
31 | {
32 | this.richTextBoxLogControl1 = new Serilog.Sinks.WinForms.RichTextBoxLogControl();
33 | this.SuspendLayout();
34 | //
35 | // richTextBoxLogControl1
36 | //
37 | this.richTextBoxLogControl1.BackColor = System.Drawing.Color.White;
38 | this.richTextBoxLogControl1.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
39 | this.richTextBoxLogControl1.ForeColor = System.Drawing.Color.Black;
40 | this.richTextBoxLogControl1.Location = new System.Drawing.Point(12, 21);
41 | this.richTextBoxLogControl1.Name = "richTextBoxLogControl1";
42 | this.richTextBoxLogControl1.ScrollBars = System.Windows.Forms.RichTextBoxScrollBars.Vertical;
43 | this.richTextBoxLogControl1.Size = new System.Drawing.Size(776, 417);
44 | this.richTextBoxLogControl1.TabIndex = 0;
45 | this.richTextBoxLogControl1.Text = "";
46 | //
47 | // RichTextBoxLogControlForm
48 | //
49 | this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
50 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
51 | this.ClientSize = new System.Drawing.Size(800, 450);
52 | this.Controls.Add(this.richTextBoxLogControl1);
53 | this.Name = "RichTextBoxLogControlForm";
54 | this.Text = "RichTextBoxLogControlForm";
55 | this.ResumeLayout(false);
56 |
57 | }
58 |
59 | #endregion
60 |
61 | private Serilog.Sinks.WinForms.RichTextBoxLogControl richTextBoxLogControl1;
62 | }
63 | }
--------------------------------------------------------------------------------
/src/Sample/TestApplication/RichTextBoxLogControlForm.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.ComponentModel;
4 | using System.Data;
5 | using System.Drawing;
6 | using System.Linq;
7 | using System.Text;
8 | using System.Threading.Tasks;
9 | using System.Windows.Forms;
10 |
11 | namespace TestApplication
12 | {
13 | public partial class RichTextBoxLogControlForm : Form
14 | {
15 | public RichTextBoxLogControlForm()
16 | {
17 | InitializeComponent();
18 | }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/src/Sample/TestApplication/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/src/Sample/TestApplicationNet6/Form1.Designer.cs:
--------------------------------------------------------------------------------
1 | namespace TestApplicationNet6
2 | {
3 | partial class Form1
4 | {
5 | ///
6 | /// Required designer variable.
7 | ///
8 | private System.ComponentModel.IContainer components = null;
9 |
10 | ///
11 | /// Clean up any resources being used.
12 | ///
13 | /// true if managed resources should be disposed; otherwise, false.
14 | protected override void Dispose(bool disposing)
15 | {
16 | if (disposing && (components != null))
17 | {
18 | components.Dispose();
19 | }
20 | base.Dispose(disposing);
21 | }
22 |
23 | #region Windows Form Designer generated code
24 |
25 | ///
26 | /// Required method for Designer support - do not modify
27 | /// the contents of this method with the code editor.
28 | ///
29 | private void InitializeComponent()
30 | {
31 | simpleLogTextBox1 = new Serilog.Sinks.WinForms.Core.SimpleLogTextBox();
32 | txtLog = new TextBox();
33 | btnWriteLog = new Button();
34 | jsonLogTextBox1 = new Serilog.Sinks.WinForms.Core.JsonLogTextBox();
35 | richTextBoxLogControl1 = new Serilog.Sinks.WinForms.Core.RichTextBoxLogControl();
36 | SuspendLayout();
37 | //
38 | // simpleLogTextBox1
39 | //
40 | simpleLogTextBox1.Location = new Point(13, 79);
41 | simpleLogTextBox1.Margin = new Padding(4, 3, 4, 3);
42 | simpleLogTextBox1.Name = "simpleLogTextBox1";
43 | simpleLogTextBox1.Size = new Size(774, 148);
44 | simpleLogTextBox1.TabIndex = 0;
45 | simpleLogTextBox1.AutoPurge = true;
46 | simpleLogTextBox1.AutoPurgeTime = 1;
47 | //
48 | // txtLog
49 | //
50 | txtLog.Location = new Point(32, 19);
51 | txtLog.Name = "txtLog";
52 | txtLog.Size = new Size(580, 23);
53 | txtLog.TabIndex = 1;
54 | //
55 | // btnWriteLog
56 | //
57 | btnWriteLog.Location = new Point(618, 18);
58 | btnWriteLog.Name = "btnWriteLog";
59 | btnWriteLog.Size = new Size(169, 23);
60 | btnWriteLog.TabIndex = 2;
61 | btnWriteLog.Text = "Write Log";
62 | btnWriteLog.UseVisualStyleBackColor = true;
63 | btnWriteLog.Click += btnWriteLog_Click;
64 | //
65 | // jsonLogTextBox1
66 | //
67 | jsonLogTextBox1.Location = new Point(13, 242);
68 | jsonLogTextBox1.Margin = new Padding(4, 3, 4, 3);
69 | jsonLogTextBox1.Name = "jsonLogTextBox1";
70 | jsonLogTextBox1.Size = new Size(774, 210);
71 | jsonLogTextBox1.TabIndex = 3;
72 | //
73 | // richTextBoxLogControl1
74 | //
75 | richTextBoxLogControl1.Location = new Point(13, 469);
76 | richTextBoxLogControl1.Name = "richTextBoxLogControl1";
77 | richTextBoxLogControl1.Size = new Size(774, 164);
78 | richTextBoxLogControl1.TabIndex = 4;
79 | richTextBoxLogControl1.Text = "";
80 | //
81 | // Form1
82 | //
83 | AutoScaleDimensions = new SizeF(7F, 15F);
84 | AutoScaleMode = AutoScaleMode.Font;
85 | ClientSize = new Size(1015, 658);
86 | Controls.Add(richTextBoxLogControl1);
87 | Controls.Add(jsonLogTextBox1);
88 | Controls.Add(btnWriteLog);
89 | Controls.Add(txtLog);
90 | Controls.Add(simpleLogTextBox1);
91 | Name = "Form1";
92 | Text = "Form1";
93 | ResumeLayout(false);
94 | PerformLayout();
95 | }
96 |
97 | #endregion
98 |
99 | private Serilog.Sinks.WinForms.Core.SimpleLogTextBox simpleLogTextBox1;
100 | private TextBox txtLog;
101 | private Button btnWriteLog;
102 | private Serilog.Sinks.WinForms.Core.JsonLogTextBox jsonLogTextBox1;
103 | private Serilog.Sinks.WinForms.Core.RichTextBoxLogControl richTextBoxLogControl1;
104 | }
105 | }
--------------------------------------------------------------------------------
/src/Sample/TestApplicationNet6/Form1.cs:
--------------------------------------------------------------------------------
1 | using Serilog;
2 |
3 | namespace TestApplicationNet6
4 | {
5 | public partial class Form1 : Form
6 | {
7 | public Form1()
8 | {
9 | InitializeComponent();
10 | }
11 |
12 | private void btnWriteLog_Click(object sender, EventArgs e)
13 | {
14 | Log.Information("This is the Text log..");
15 | Log.Information(txtLog.Text);
16 | }
17 | }
18 | }
--------------------------------------------------------------------------------
/src/Sample/TestApplicationNet6/Form1.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 | text/microsoft-resx
110 |
111 |
112 | 2.0
113 |
114 |
115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
119 |
120 |
--------------------------------------------------------------------------------
/src/Sample/TestApplicationNet6/Program.cs:
--------------------------------------------------------------------------------
1 | using Serilog;
2 | using Serilog.Sinks.WinForms.Base;
3 |
4 | namespace TestApplicationNet6
5 | {
6 | internal static class Program
7 | {
8 | ///
9 | /// The main entry point for the application.
10 | ///
11 | [STAThread]
12 | static void Main()
13 | {
14 | ConfigureSerilog();
15 |
16 | // To customize application configuration such as set high DPI settings or default font,
17 | // see https://aka.ms/applicationconfiguration.
18 | ApplicationConfiguration.Initialize();
19 | Application.Run(new Form1());
20 | }
21 |
22 | private static void ConfigureSerilog()
23 | {
24 | Log.Logger = new LoggerConfiguration()
25 | .Enrich.FromLogContext()
26 | .WriteToGridView()
27 | .WriteToJsonTextBox()
28 | .WriteToSimpleAndRichTextBox()
29 | .CreateLogger();
30 | }
31 | }
32 | }
--------------------------------------------------------------------------------
/src/Sample/TestApplicationNet6/TestApplicationNet9.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | WinExe
5 | net9.0-windows
6 | enable
7 | true
8 | enable
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/src/Sample/TestApplicationWithTransparentBackground/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/src/Sample/TestApplicationWithTransparentBackground/Form1.Designer.cs:
--------------------------------------------------------------------------------
1 |
2 | namespace TestApplicationWithTransparentBackground
3 | {
4 | partial class Form1
5 | {
6 | ///
7 | /// Required designer variable.
8 | ///
9 | private System.ComponentModel.IContainer components = null;
10 |
11 | ///
12 | /// Clean up any resources being used.
13 | ///
14 | /// true if managed resources should be disposed; otherwise, false.
15 | protected override void Dispose(bool disposing)
16 | {
17 | if (disposing && (components != null))
18 | {
19 | components.Dispose();
20 | }
21 | base.Dispose(disposing);
22 | }
23 |
24 | #region Windows Form Designer generated code
25 |
26 | ///
27 | /// Required method for Designer support - do not modify
28 | /// the contents of this method with the code editor.
29 | ///
30 | private void InitializeComponent()
31 | {
32 | this.button1 = new System.Windows.Forms.Button();
33 | this.transparentSimpleLogTextBox1 = new Serilog.Sinks.WinForms.TransparentSimpleLogTextBox();
34 | this.SuspendLayout();
35 | //
36 | // button1
37 | //
38 | this.button1.Location = new System.Drawing.Point(12, 30);
39 | this.button1.Name = "button1";
40 | this.button1.Size = new System.Drawing.Size(433, 71);
41 | this.button1.TabIndex = 1;
42 | this.button1.Text = "Generate log";
43 | this.button1.UseVisualStyleBackColor = true;
44 | this.button1.Click += new System.EventHandler(this.button1_Click);
45 | //
46 | // transparentSimpleLogTextBox1
47 | //
48 | this.transparentSimpleLogTextBox1.BackColor = System.Drawing.Color.Transparent;
49 | this.transparentSimpleLogTextBox1.Location = new System.Drawing.Point(13, 135);
50 | this.transparentSimpleLogTextBox1.Multiline = true;
51 | this.transparentSimpleLogTextBox1.Name = "transparentSimpleLogTextBox1";
52 | this.transparentSimpleLogTextBox1.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
53 | this.transparentSimpleLogTextBox1.Size = new System.Drawing.Size(775, 173);
54 | this.transparentSimpleLogTextBox1.TabIndex = 2;
55 | //
56 | // Form1
57 | //
58 | this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
59 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
60 | this.BackColor = System.Drawing.SystemColors.Control;
61 | this.ClientSize = new System.Drawing.Size(800, 320);
62 | this.Controls.Add(this.transparentSimpleLogTextBox1);
63 | this.Controls.Add(this.button1);
64 | this.Name = "Form1";
65 | this.Text = "Form1";
66 | this.ResumeLayout(false);
67 | this.PerformLayout();
68 |
69 | }
70 |
71 | #endregion
72 |
73 | private System.Windows.Forms.Button button1;
74 | private Serilog.Sinks.WinForms.TransparentSimpleLogTextBox transparentSimpleLogTextBox1;
75 | }
76 | }
77 |
78 |
--------------------------------------------------------------------------------
/src/Sample/TestApplicationWithTransparentBackground/Form1.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.ComponentModel;
4 | using System.Data;
5 | using System.Drawing;
6 | using System.Linq;
7 | using System.Text;
8 | using System.Threading.Tasks;
9 | using System.Windows.Forms;
10 | using Serilog;
11 |
12 | namespace TestApplicationWithTransparentBackground
13 | {
14 | public partial class Form1 : Form
15 | {
16 | public Form1()
17 | {
18 | this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);
19 | InitializeComponent();
20 |
21 | }
22 |
23 | private void button1_Click(object sender, EventArgs e)
24 | {
25 | Log.Information("Testing");
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/src/Sample/TestApplicationWithTransparentBackground/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Threading.Tasks;
5 | using System.Windows.Forms;
6 |
7 | using Serilog;
8 | using Serilog.Sinks.WinForms.Base;
9 |
10 | namespace TestApplicationWithTransparentBackground
11 | {
12 | static class Program
13 | {
14 | ///
15 | /// The main entry point for the application.
16 | ///
17 | [STAThread]
18 | static void Main()
19 | {
20 | Log.Logger = new LoggerConfiguration()
21 | .WriteToSimpleAndRichTextBox()
22 | .CreateLogger();
23 | Application.EnableVisualStyles();
24 | Application.SetCompatibleTextRenderingDefault(false);
25 | Application.Run(new Form1());
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/src/Sample/TestApplicationWithTransparentBackground/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("TestApplicationWithTransparentBackground")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("TestApplicationWithTransparentBackground")]
13 | [assembly: AssemblyCopyright("Copyright © 2021")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("65d7c21e-45ec-46d3-b489-9cc20efff13f")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/src/Sample/TestApplicationWithTransparentBackground/Properties/Resources.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.42000
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 |
12 | namespace TestApplicationWithTransparentBackground.Properties
13 | {
14 | ///
15 | /// A strongly-typed resource class, for looking up localized strings, etc.
16 | ///
17 | // This class was auto-generated by the StronglyTypedResourceBuilder
18 | // class via a tool like ResGen or Visual Studio.
19 | // To add or remove a member, edit your .ResX file then rerun ResGen
20 | // with the /str option, or rebuild your VS project.
21 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
22 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
23 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
24 | internal class Resources
25 | {
26 |
27 | private static global::System.Resources.ResourceManager resourceMan;
28 |
29 | private static global::System.Globalization.CultureInfo resourceCulture;
30 |
31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
32 | internal Resources()
33 | {
34 | }
35 |
36 | ///
37 | /// Returns the cached ResourceManager instance used by this class.
38 | ///
39 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
40 | internal static global::System.Resources.ResourceManager ResourceManager
41 | {
42 | get
43 | {
44 | if ((resourceMan == null))
45 | {
46 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("TestApplicationWithTransparentBackground.Properties.Resources", typeof(Resources).Assembly);
47 | resourceMan = temp;
48 | }
49 | return resourceMan;
50 | }
51 | }
52 |
53 | ///
54 | /// Overrides the current thread's CurrentUICulture property for all
55 | /// resource lookups using this strongly typed resource class.
56 | ///
57 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
58 | internal static global::System.Globalization.CultureInfo Culture
59 | {
60 | get
61 | {
62 | return resourceCulture;
63 | }
64 | set
65 | {
66 | resourceCulture = value;
67 | }
68 | }
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/src/Sample/TestApplicationWithTransparentBackground/Properties/Resources.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 | text/microsoft-resx
107 |
108 |
109 | 2.0
110 |
111 |
112 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
113 |
114 |
115 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
--------------------------------------------------------------------------------
/src/Sample/TestApplicationWithTransparentBackground/Properties/Settings.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.42000
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 |
12 | namespace TestApplicationWithTransparentBackground.Properties
13 | {
14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase
17 | {
18 |
19 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
20 |
21 | public static Settings Default
22 | {
23 | get
24 | {
25 | return defaultInstance;
26 | }
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/Sample/TestApplicationWithTransparentBackground/Properties/Settings.settings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/src/Sample/TestApplicationWithTransparentBackground/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/src/Serilog.Sinks.WinForms.Base/GridLogEvent.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | using Serilog.Events;
4 |
5 | namespace Serilog.Sinks.WinForms.Base
6 | {
7 | public class GridLogEvent
8 | {
9 | public DateTimeOffset TimeStamp { get; set; }
10 |
11 | public LogEventLevel Level { get; set; }
12 |
13 | public string Message { get; set; }
14 | }
15 | }
--------------------------------------------------------------------------------
/src/Serilog.Sinks.WinForms.Base/Serilog.Sinks.WinForms.Base.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netstandard2.0
5 |
6 |
7 | false
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/src/Serilog.Sinks.WinForms.Base/WinFormsSinkInternal.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IO;
3 |
4 | using Serilog.Core;
5 | using Serilog.Events;
6 | using Serilog.Formatting;
7 | using Serilog.Formatting.Display;
8 | using Serilog.Formatting.Json;
9 |
10 | namespace Serilog.Sinks.WinForms.Base
11 | {
12 | public sealed class WinFormsSinkInternal : ILogEventSink
13 | {
14 | public delegate void LogHandler(string sourceContext, string str);
15 |
16 | public event LogHandler OnLogReceived;
17 |
18 | public delegate void GridLogHandler(GridLogEvent logEvent);
19 |
20 | public event GridLogHandler OnGridLogReceived;
21 |
22 | private readonly ITextFormatter _textFormatter;
23 |
24 | private readonly bool _isGridLogger;
25 |
26 | public WinFormsSinkInternal(ITextFormatter textFormatter, bool isGridLogger = false)
27 | {
28 | _textFormatter = textFormatter;
29 | _isGridLogger = isGridLogger;
30 | }
31 |
32 | public void Emit(LogEvent logEvent)
33 | {
34 | if (logEvent == null)
35 | {
36 | throw new ArgumentNullException(nameof(logEvent));
37 | }
38 |
39 | if (_textFormatter == null)
40 | {
41 | throw new ArgumentNullException($"Missing Log Formatter");
42 | }
43 |
44 | var renderSpace = new StringWriter();
45 | _textFormatter.Format(logEvent, renderSpace);
46 |
47 | if (_isGridLogger)
48 | {
49 | OnGridLogReceived?.Invoke(new GridLogEvent { Level = logEvent.Level, TimeStamp = logEvent.Timestamp, Message = renderSpace.ToString() });
50 |
51 | return;
52 | }
53 |
54 | logEvent.Properties.TryGetValue("SourceContext", out var contextProperty);
55 |
56 | FireEvent(contextProperty?.ToString().Trim('"'), renderSpace.ToString());
57 | }
58 |
59 | private void FireEvent(string context, string str)
60 | {
61 | OnLogReceived?.Invoke(context, str);
62 | }
63 | }
64 |
65 | public static class WindFormsSink
66 | {
67 | private static readonly ITextFormatter _defaultTextFormatter = new MessageTemplateTextFormatter("{Timestamp:HH:mm:ss} {Level} {Message:lj}{NewLine}{Exception}");
68 | private static readonly ITextFormatter _defaultGridTextFormatter = new MessageTemplateTextFormatter("{Message:lj}{Exception}");
69 |
70 | public static WinFormsSinkInternal SimpleTextBoxSink { get; private set; } = new WinFormsSinkInternal(_defaultTextFormatter);
71 |
72 | public static WinFormsSinkInternal JsonTextBoxSink { get; private set; } = new WinFormsSinkInternal(new JsonFormatter());
73 |
74 | public static WinFormsSinkInternal GridLogSink { get; private set; } = new WinFormsSinkInternal(_defaultGridTextFormatter, true);
75 |
76 | public static WinFormsSinkInternal MakeSimpleTextBoxSink(ITextFormatter formatter = null)
77 | {
78 | if (formatter == null) { formatter = _defaultTextFormatter; }
79 |
80 | SimpleTextBoxSink = new WinFormsSinkInternal(formatter);
81 |
82 | return SimpleTextBoxSink;
83 | }
84 |
85 | public static WinFormsSinkInternal MakeJsonTextBoxSink(ITextFormatter formatter = null)
86 | {
87 | if (formatter == null) { formatter = new JsonFormatter(); }
88 |
89 | JsonTextBoxSink = new WinFormsSinkInternal(formatter);
90 |
91 | return JsonTextBoxSink;
92 | }
93 |
94 | public static WinFormsSinkInternal MakeGridLoggerSink(string outputFormat)
95 | {
96 | if (string.IsNullOrEmpty(outputFormat))
97 | {
98 | return GridLogSink;
99 | }
100 |
101 | GridLogSink = new WinFormsSinkInternal(new MessageTemplateTextFormatter(outputFormat), true);
102 |
103 | return GridLogSink;
104 | }
105 | }
106 | }
107 |
--------------------------------------------------------------------------------
/src/Serilog.Sinks.WinForms.Base/WindFromsSinkExtensions.cs:
--------------------------------------------------------------------------------
1 | using Serilog.Formatting;
2 |
3 | namespace Serilog.Sinks.WinForms.Base
4 | {
5 | public static class WindFromsSinkExtensions
6 | {
7 | ///
8 | /// Write the simple formatted text logs directly to textbox. simple and rich textbox control can be used from toolbox
9 | ///
10 | ///
11 | ///
12 | public static LoggerConfiguration WriteToSimpleAndRichTextBox(this LoggerConfiguration configuration, ITextFormatter formatter = null)
13 | {
14 | return configuration.WriteTo.Sink(WindFormsSink.MakeSimpleTextBoxSink(formatter));
15 | }
16 |
17 | ///
18 | /// Write the compact json formatted text logs directly to textbox. json textbox control can be used from toolbox
19 | ///
20 | ///
21 | ///
22 | public static LoggerConfiguration WriteToJsonTextBox(this LoggerConfiguration configuration, ITextFormatter formatter = null)
23 | {
24 | return configuration.WriteTo.Sink(WindFormsSink.MakeJsonTextBoxSink(formatter));
25 | }
26 |
27 | ///
28 | /// Write the logs directly to Data Grid View. GridLog control can be used from toolbox
29 | ///
30 | ///
31 | ///
32 | public static LoggerConfiguration WriteToGridView(this LoggerConfiguration configuration, string outputformat = null)
33 | {
34 | return configuration.WriteTo.Sink(WindFormsSink.MakeGridLoggerSink(outputformat));
35 | }
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/Serilog.Sinks.WinForms.Core/GridLog.Designer.cs:
--------------------------------------------------------------------------------
1 | namespace Serilog.Sinks.WinForms.Core
2 | {
3 | partial class GridLog
4 | {
5 | ///
6 | /// Required designer variable.
7 | ///
8 | private System.ComponentModel.IContainer components = null;
9 |
10 | ///
11 | /// Clean up any resources being used.
12 | ///
13 | /// true if managed resources should be disposed; otherwise, false.
14 | protected override void Dispose(bool disposing)
15 | {
16 | if (disposing && (components != null))
17 | {
18 | components.Dispose();
19 | }
20 | base.Dispose(disposing);
21 | }
22 |
23 | #region Component Designer generated code
24 |
25 | ///
26 | /// Required method for Designer support - do not modify
27 | /// the contents of this method with the code editor.
28 | ///
29 | private void InitializeComponent()
30 | {
31 | System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle();
32 | this.LogGridView = new System.Windows.Forms.DataGridView();
33 | this.TimeStamp = new System.Windows.Forms.DataGridViewTextBoxColumn();
34 | this.Level = new System.Windows.Forms.DataGridViewTextBoxColumn();
35 | this.Log = new System.Windows.Forms.DataGridViewTextBoxColumn();
36 | ((System.ComponentModel.ISupportInitialize)(this.LogGridView)).BeginInit();
37 | this.SuspendLayout();
38 | //
39 | // LogGridView
40 | //
41 | this.LogGridView.AllowUserToAddRows = false;
42 | this.LogGridView.AllowUserToDeleteRows = false;
43 | this.LogGridView.BackgroundColor = System.Drawing.SystemColors.Control;
44 | this.LogGridView.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
45 | this.LogGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
46 | this.LogGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
47 | this.TimeStamp,
48 | this.Level,
49 | this.Log});
50 | this.LogGridView.Dock = System.Windows.Forms.DockStyle.Fill;
51 | this.LogGridView.Location = new System.Drawing.Point(0, 0);
52 | this.LogGridView.Name = "LogGridView";
53 | this.LogGridView.ReadOnly = true;
54 | this.LogGridView.RowHeadersVisible = false;
55 | this.LogGridView.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.CellSelect;
56 | this.LogGridView.Size = new System.Drawing.Size(358, 150);
57 | this.LogGridView.TabIndex = 0;
58 | //
59 | // TimeStamp
60 | //
61 | this.TimeStamp.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
62 | this.TimeStamp.HeaderText = "TimeStamp";
63 | this.TimeStamp.Name = "TimeStamp";
64 | this.TimeStamp.ReadOnly = true;
65 | this.TimeStamp.Width = 85;
66 | //
67 | // Level
68 | //
69 | this.Level.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
70 | this.Level.HeaderText = "Level";
71 | this.Level.Name = "Level";
72 | this.Level.ReadOnly = true;
73 | this.Level.Width = 58;
74 | //
75 | // Log
76 | //
77 | this.Log.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
78 | dataGridViewCellStyle1.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
79 | this.Log.DefaultCellStyle = dataGridViewCellStyle1;
80 | this.Log.HeaderText = "Log";
81 | this.Log.Name = "Log";
82 | this.Log.ReadOnly = true;
83 | //
84 | // GridLog
85 | //
86 | this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
87 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
88 | this.Controls.Add(this.LogGridView);
89 | this.Name = "GridLog";
90 | this.Size = new System.Drawing.Size(358, 150);
91 | this.Load += new System.EventHandler(this.GridLog_Load);
92 | ((System.ComponentModel.ISupportInitialize)(this.LogGridView)).EndInit();
93 | this.ResumeLayout(false);
94 |
95 | }
96 |
97 | #endregion
98 |
99 | private System.Windows.Forms.DataGridView LogGridView;
100 | private System.Windows.Forms.DataGridViewTextBoxColumn TimeStamp;
101 | private System.Windows.Forms.DataGridViewTextBoxColumn Level;
102 | private System.Windows.Forms.DataGridViewTextBoxColumn Log;
103 | }
104 | }
105 |
--------------------------------------------------------------------------------
/src/Serilog.Sinks.WinForms.Core/GridLog.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Windows.Forms;
3 | using Serilog.Sinks.WinForms.Base;
4 |
5 | namespace Serilog.Sinks.WinForms.Core
6 | {
7 | public partial class GridLog : UserControl
8 | {
9 | public GridLog()
10 | {
11 | InitializeComponent();
12 | }
13 |
14 | private void GridLog_Load(object sender, EventArgs e)
15 | {
16 | LogGridView.Font = this.Font;
17 |
18 | WindFormsSink.GridLogSink.OnGridLogReceived += GridLogSink_OnGridLogReceived;
19 |
20 | HandleDestroyed += (handler, args) =>
21 | {
22 | WindFormsSink.GridLogSink.OnGridLogReceived -= GridLogSink_OnGridLogReceived;
23 | };
24 | }
25 |
26 | private void GridLogSink_OnGridLogReceived(GridLogEvent logEvent)
27 | {
28 | if (this.InvokeRequired)
29 | {
30 | this.Invoke(
31 | (MethodInvoker)delegate
32 | {
33 | LogGridView.Rows.Add(logEvent.TimeStamp.ToString(), logEvent.Level, logEvent.Message?.Trim());
34 | LogGridView.FirstDisplayedScrollingRowIndex = LogGridView.RowCount - 1;
35 | });
36 | }
37 | else
38 | {
39 | LogGridView.Rows.Add(logEvent.TimeStamp.ToString(), logEvent.Level, logEvent.Message);
40 | LogGridView.FirstDisplayedScrollingRowIndex = LogGridView.RowCount - 1;
41 | }
42 |
43 | Application.DoEvents();
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/src/Serilog.Sinks.WinForms.Core/JsonLogTextBox.Designer.cs:
--------------------------------------------------------------------------------
1 | namespace Serilog.Sinks.WinForms.Core
2 | {
3 | partial class JsonLogTextBox
4 | {
5 | ///
6 | /// Required designer variable.
7 | ///
8 | private System.ComponentModel.IContainer components = null;
9 |
10 | ///
11 | /// Clean up any resources being used.
12 | ///
13 | /// true if managed resources should be disposed; otherwise, false.
14 | protected override void Dispose(bool disposing)
15 | {
16 | if (disposing && (components != null))
17 | {
18 | components.Dispose();
19 | }
20 | base.Dispose(disposing);
21 | }
22 |
23 | #region Component Designer generated code
24 |
25 | ///
26 | /// Required method for Designer support - do not modify
27 | /// the contents of this method with the code editor.
28 | ///
29 | private void InitializeComponent()
30 | {
31 | this.TxtLogControl = new System.Windows.Forms.TextBox();
32 | this.SuspendLayout();
33 | //
34 | // TxtLogControl
35 | //
36 | this.TxtLogControl.Dock = System.Windows.Forms.DockStyle.Fill;
37 | this.TxtLogControl.Location = new System.Drawing.Point(0, 0);
38 | this.TxtLogControl.Multiline = true;
39 | this.TxtLogControl.Name = "TxtLogControl";
40 | this.TxtLogControl.Size = new System.Drawing.Size(372, 158);
41 | this.TxtLogControl.TabIndex = 0;
42 | //
43 | // LogTextBox
44 | //
45 | this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
46 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
47 | this.Controls.Add(this.TxtLogControl);
48 | this.Name = "LogTextBox";
49 | this.Size = new System.Drawing.Size(372, 158);
50 | this.Load += new System.EventHandler(this.LogTextBox_Load);
51 | this.ResumeLayout(false);
52 | this.PerformLayout();
53 |
54 | }
55 |
56 | #endregion
57 |
58 | private System.Windows.Forms.TextBox TxtLogControl;
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/src/Serilog.Sinks.WinForms.Core/JsonLogTextBox.cs:
--------------------------------------------------------------------------------
1 | using System.ComponentModel;
2 | using Serilog.Sinks.WinForms.Base;
3 |
4 | namespace Serilog.Sinks.WinForms.Core
5 | {
6 | public partial class JsonLogTextBox : UserControl
7 | {
8 | [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
9 | public ScrollBars ScrollBars { get; set; }
10 |
11 | [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
12 | public Padding LogPadding { get; set; } = new Padding(3, 3, 3, 3);
13 |
14 | [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
15 | public bool ReadOnly { get; set; }
16 |
17 | [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
18 | public BorderStyle LogBorderStyle { get; set; } = BorderStyle.Fixed3D;
19 | [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
20 | public string ForContext { get; set; } = string.Empty;
21 |
22 | private bool _isContextConfigured = false;
23 |
24 | public JsonLogTextBox()
25 | {
26 | InitializeComponent();
27 | }
28 |
29 | private void LogTextBox_Load(object sender, EventArgs e)
30 | {
31 | TxtLogControl.ScrollBars = ScrollBars;
32 | TxtLogControl.Padding = LogPadding;
33 | TxtLogControl.ReadOnly = ReadOnly;
34 | TxtLogControl.BorderStyle = LogBorderStyle;
35 | TxtLogControl.Font = this.Font;
36 | TxtLogControl.ForeColor = this.ForeColor;
37 | TxtLogControl.BackColor = this.BackColor;
38 | WindFormsSink.JsonTextBoxSink.OnLogReceived += JsonTextBoxSinkOnLogReceived;
39 |
40 | HandleDestroyed += ( handler, args ) =>
41 | {
42 | WindFormsSink.JsonTextBoxSink.OnLogReceived -= JsonTextBoxSinkOnLogReceived;
43 | };
44 | }
45 |
46 | private void JsonTextBoxSinkOnLogReceived(string context, string str)
47 | {
48 | if (_isContextConfigured)
49 | {
50 | if (!string.IsNullOrEmpty(this.ForContext)
51 | && !string.IsNullOrEmpty(context)
52 | && this.ForContext.Equals(context, StringComparison.InvariantCultureIgnoreCase)) { PrintText(str); }
53 | }
54 | else
55 | {
56 | PrintText(str);
57 | }
58 |
59 | Application.DoEvents();
60 | }
61 |
62 | private void PrintText(string str)
63 | {
64 | if (this.InvokeRequired)
65 | {
66 | this.Invoke(
67 | (MethodInvoker)delegate
68 | {
69 | TxtLogControl.AppendText(str);
70 | TxtLogControl.ScrollToCaret();
71 | });
72 | }
73 | else
74 | {
75 | TxtLogControl.AppendText(str);
76 | TxtLogControl.ScrollToCaret();
77 | }
78 | }
79 |
80 | public void ClearLogs()
81 | {
82 | if (this.InvokeRequired)
83 | {
84 | this.Invoke((MethodInvoker)(() => TxtLogControl.Clear()));
85 | }
86 | else
87 | {
88 | TxtLogControl.Clear();
89 | }
90 | }
91 |
92 | public void SaveLogToFile()
93 | {
94 | SaveFileHelper.SaveLogsToFile(TxtLogControl.Text);
95 | }
96 | }
97 | }
--------------------------------------------------------------------------------
/src/Serilog.Sinks.WinForms.Core/JsonLogTextBox.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 | text/microsoft-resx
110 |
111 |
112 | 2.0
113 |
114 |
115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
119 |
120 |
--------------------------------------------------------------------------------
/src/Serilog.Sinks.WinForms.Core/RichTextBoxLogControl.Designer.cs:
--------------------------------------------------------------------------------
1 |
2 | namespace Serilog.Sinks.WinForms.Core
3 | {
4 | partial class RichTextBoxLogControl
5 | {
6 | ///
7 | /// Required designer variable.
8 | ///
9 | private System.ComponentModel.IContainer components = null;
10 |
11 | ///
12 | /// Clean up any resources being used.
13 | ///
14 | /// true if managed resources should be disposed; otherwise, false.
15 | protected override void Dispose(bool disposing)
16 | {
17 | if (disposing && (components != null))
18 | {
19 | components.Dispose();
20 | }
21 | base.Dispose(disposing);
22 | }
23 |
24 | #region Component Designer generated code
25 |
26 | ///
27 | /// Required method for Designer support - do not modify
28 | /// the contents of this method with the code editor.
29 | ///
30 | private void InitializeComponent()
31 | {
32 | components = new System.ComponentModel.Container();
33 | }
34 |
35 | #endregion
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/Serilog.Sinks.WinForms.Core/RichTextBoxLogControl.cs:
--------------------------------------------------------------------------------
1 | using System.ComponentModel;
2 | using Serilog.Sinks.WinForms.Base;
3 |
4 | namespace Serilog.Sinks.WinForms.Core
5 | {
6 | public partial class RichTextBoxLogControl : RichTextBox
7 | {
8 | [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
9 | [Category("Serilog Sink WinForms")] public string ForContext { get; set; } = string.Empty;
10 |
11 | [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
12 | [Category("Serilog Sink WinForms")] public bool AutoPurge { get; set; }
13 |
14 | [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
15 | [Category("Serilog Sink WinForms")] public double AutoPurgeTime { get; set; } = 60;
16 |
17 | private System.Windows.Forms.Timer _timer = default!;
18 |
19 | public RichTextBoxLogControl()
20 | {
21 | InitializeComponent();
22 | WindFormsSink.SimpleTextBoxSink.OnLogReceived += SimpleTextBoxSinkOnLogReceived;
23 |
24 | HandleDestroyed += (sender, args) =>
25 | {
26 | WindFormsSink.SimpleTextBoxSink.OnLogReceived -= SimpleTextBoxSinkOnLogReceived;
27 | };
28 |
29 | if (AutoPurge)
30 | {
31 | _timer = new System.Windows.Forms.Timer
32 | {
33 | Interval = Convert.ToInt32(TimeSpan.FromMinutes(AutoPurgeTime).TotalMilliseconds)
34 | };
35 | _timer.Tick += _timer_Tick;
36 | _timer.Start();
37 | }
38 | }
39 |
40 | private void _timer_Tick(object sender, EventArgs e)
41 | {
42 | ClearLogs();
43 | }
44 |
45 | private void SimpleTextBoxSinkOnLogReceived(string context, string str)
46 | {
47 | if (!string.IsNullOrEmpty(this.ForContext.Trim()))
48 | {
49 | if (!string.IsNullOrEmpty(context)
50 | && this.ForContext.Equals(context, StringComparison.InvariantCultureIgnoreCase)) { PrintText(str); }
51 | }
52 | else
53 | {
54 | PrintText(str);
55 | }
56 |
57 | Application.DoEvents();
58 | }
59 |
60 | private void PrintText(string str)
61 | {
62 | if (this.InvokeRequired)
63 | {
64 | this.Invoke((MethodInvoker)delegate
65 | {
66 | this.AppendText(str);
67 | this.ScrollToCaret();
68 | });
69 | }
70 | else
71 | {
72 | this.AppendText(str);
73 | this.ScrollToCaret();
74 | }
75 | }
76 |
77 | public void ClearLogs()
78 | {
79 | if (this.InvokeRequired)
80 | {
81 | this.Invoke((MethodInvoker)(() => this.Clear()));
82 | }
83 | else
84 | {
85 | this.Clear();
86 | }
87 | }
88 |
89 | public void SaveLogToFile()
90 | {
91 | SaveFileHelper.SaveLogsToFile(this.Text);
92 | }
93 | }
94 | }
--------------------------------------------------------------------------------
/src/Serilog.Sinks.WinForms.Core/SaveFileHelper.cs:
--------------------------------------------------------------------------------
1 | namespace Serilog.Sinks.WinForms.Core
2 | {
3 | public static class SaveFileHelper
4 | {
5 | internal static void SaveLogsToFile(string fileContent)
6 | {
7 | try
8 | {
9 | var saveFileDialog = new SaveFileDialog { Filter = @"Text Files | *.txt| Log Files |*.log" };
10 |
11 | if (saveFileDialog.ShowDialog() == DialogResult.OK)
12 | {
13 | File.AppendAllText(saveFileDialog.FileName, fileContent);
14 | }
15 | }
16 | catch (Exception e)
17 | {
18 | MessageBox.Show(e.Message, @"Error Saving Log File", MessageBoxButtons.OK, MessageBoxIcon.Error);
19 | }
20 | }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/src/Serilog.Sinks.WinForms.Core/Serilog.Sinks.WinForms.Core.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net6.0-windows;net8.0-windows;net9.0-windows
5 | enable
6 | true
7 | enable
8 | latest
9 | Writes Serilog events to Windows Forms Application TextBox or Datagridview control from anywhere in your application.
10 | 2.0.0
11 | UmairSyed (@umairsyed613)
12 | https://github.com/umairsyed613/Serilog.Sinks.WinForms
13 | images\icon.png
14 | https://github.com/umairsyed613/Serilog.Sinks.WinForms/blob/main/assets/serilog-sink-nuget.png
15 | Copyright © 2022
16 | https://github.com/umairsyed613/Serilog.Sinks.WinForms
17 | git
18 | Serilog
19 | Serilog;Serilog-windows-forms;windowsforms-windowsformnet5;serilognet6;serilognet5;serilogwindowsforms
20 | Read Docs at https://github.com/umairsyed613/Serilog.Sinks.WinForms
21 | en
22 | MIT
23 | False
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 | $(TargetsForTfmSpecificBuildOutput);IncludeP2PAssets
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/src/Serilog.Sinks.WinForms.Core/SimpleLogTextBox.Designer.cs:
--------------------------------------------------------------------------------
1 | namespace Serilog.Sinks.WinForms.Core
2 | {
3 | partial class SimpleLogTextBox
4 | {
5 | ///
6 | /// Required designer variable.
7 | ///
8 | private System.ComponentModel.IContainer components = null;
9 |
10 | ///
11 | /// Clean up any resources being used.
12 | ///
13 | /// true if managed resources should be disposed; otherwise, false.
14 | protected override void Dispose(bool disposing)
15 | {
16 | if (disposing && (components != null))
17 | {
18 | components.Dispose();
19 | }
20 | base.Dispose(disposing);
21 | }
22 |
23 | #region Component Designer generated code
24 |
25 | ///
26 | /// Required method for Designer support - do not modify
27 | /// the contents of this method with the code editor.
28 | ///
29 | private void InitializeComponent()
30 | {
31 | this.TxtLogControl = new System.Windows.Forms.TextBox();
32 | this.SuspendLayout();
33 | //
34 | // TxtLogControl
35 | //
36 | this.TxtLogControl.Dock = System.Windows.Forms.DockStyle.Fill;
37 | this.TxtLogControl.Location = new System.Drawing.Point(0, 0);
38 | this.TxtLogControl.Multiline = true;
39 | this.TxtLogControl.Name = "TxtLogControl";
40 | this.TxtLogControl.Size = new System.Drawing.Size(372, 158);
41 | this.TxtLogControl.TabIndex = 0;
42 | //
43 | // LogTextBox
44 | //
45 | this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
46 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
47 | this.Controls.Add(this.TxtLogControl);
48 | this.Name = "LogTextBox";
49 | this.Size = new System.Drawing.Size(372, 158);
50 | this.Load += new System.EventHandler(this.LogTextBox_Load);
51 | this.ResumeLayout(false);
52 | this.PerformLayout();
53 |
54 | }
55 |
56 | #endregion
57 |
58 | private System.Windows.Forms.TextBox TxtLogControl;
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/src/Serilog.Sinks.WinForms.Core/SimpleLogTextBox.cs:
--------------------------------------------------------------------------------
1 | using System.ComponentModel;
2 | using Serilog.Sinks.WinForms.Base;
3 |
4 | namespace Serilog.Sinks.WinForms.Core
5 | {
6 | public partial class SimpleLogTextBox : UserControl
7 | {
8 | private bool _isContextConfigured = false;
9 |
10 | [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
11 | [Category("Serilog Sink WinForms")] public ScrollBars ScrollBars { get; set; }
12 |
13 | [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
14 | [Category("Serilog Sink WinForms")] public Padding LogPadding { get; set; } = new Padding(3, 3, 3, 3);
15 |
16 | [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
17 | [Category("Serilog Sink WinForms")] public bool ReadOnly { get; set; }
18 |
19 | [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
20 | [Category("Serilog Sink WinForms")] public string ForContext { get; set; } = string.Empty;
21 |
22 | [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
23 | [Category("Serilog Sink WinForms")] public BorderStyle LogBorderStyle { get; set; } = BorderStyle.Fixed3D;
24 |
25 | [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
26 | [Category("Serilog Sink WinForms")] public bool AutoPurge { get; set; }
27 |
28 | [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
29 | [Category("Serilog Sink WinForms")] public double AutoPurgeTime { get; set; } = 60;
30 |
31 | private System.Windows.Forms.Timer _timer = default!;
32 |
33 | public SimpleLogTextBox()
34 | {
35 | InitializeComponent();
36 | }
37 |
38 | private void LogTextBox_Load(object sender, EventArgs e)
39 | {
40 | TxtLogControl.ScrollBars = ScrollBars;
41 | TxtLogControl.Padding = LogPadding;
42 | TxtLogControl.ReadOnly = ReadOnly;
43 | TxtLogControl.BorderStyle = LogBorderStyle;
44 | TxtLogControl.Font = this.Font;
45 | TxtLogControl.ForeColor = this.ForeColor;
46 | TxtLogControl.BackColor = this.BackColor;
47 | _isContextConfigured = !string.IsNullOrEmpty(this.ForContext);
48 |
49 | WindFormsSink.SimpleTextBoxSink.OnLogReceived += SimpleTextBoxSinkOnLogReceived;
50 |
51 | HandleDestroyed += (handler, args) =>
52 | {
53 | WindFormsSink.SimpleTextBoxSink.OnLogReceived -= SimpleTextBoxSinkOnLogReceived;
54 | };
55 |
56 | if (AutoPurge)
57 | {
58 | _timer = new System.Windows.Forms.Timer
59 | {
60 | Interval = Convert.ToInt32(TimeSpan.FromMinutes(AutoPurgeTime).TotalMilliseconds)
61 | };
62 | _timer.Tick += _timer_Tick;
63 | _timer.Start();
64 | }
65 | }
66 |
67 | private void _timer_Tick(object sender, EventArgs e)
68 | {
69 | ClearLogs();
70 | }
71 |
72 | private void SimpleTextBoxSinkOnLogReceived(string context, string str)
73 | {
74 | if (_isContextConfigured)
75 | {
76 | if (!string.IsNullOrEmpty(this.ForContext)
77 | && !string.IsNullOrEmpty(context)
78 | && this.ForContext.Equals(context, StringComparison.InvariantCultureIgnoreCase)) { PrintText(str); }
79 | }
80 | else
81 | {
82 | PrintText(str);
83 | }
84 |
85 | Application.DoEvents();
86 | }
87 |
88 | private void PrintText(string str)
89 | {
90 | if (this.InvokeRequired)
91 | {
92 | this.Invoke(
93 | (MethodInvoker)delegate
94 | {
95 | TxtLogControl.AppendText(str);
96 | TxtLogControl.ScrollToCaret();
97 | });
98 | }
99 | else
100 | {
101 | TxtLogControl.AppendText(str);
102 | TxtLogControl.ScrollToCaret();
103 | }
104 | }
105 |
106 | public void ClearLogs()
107 | {
108 | if (this.InvokeRequired)
109 | {
110 | this.Invoke((MethodInvoker)(() => TxtLogControl.Clear()));
111 | }
112 | else
113 | {
114 | TxtLogControl.Clear();
115 | }
116 | }
117 |
118 | public void SaveLogToFile()
119 | {
120 | SaveFileHelper.SaveLogsToFile(TxtLogControl.Text);
121 | }
122 | }
123 | }
--------------------------------------------------------------------------------
/src/Serilog.Sinks.WinForms.Core/TransparentSimpleLogTextBox.Designer.cs:
--------------------------------------------------------------------------------
1 |
2 | namespace Serilog.Sinks.WinForms.Core
3 | {
4 | partial class TransparentSimpleLogTextBox
5 | {
6 | ///
7 | /// Required designer variable.
8 | ///
9 | private System.ComponentModel.IContainer components = null;
10 |
11 | ///
12 | /// Clean up any resources being used.
13 | ///
14 | /// true if managed resources should be disposed; otherwise, false.
15 | protected override void Dispose(bool disposing)
16 | {
17 | if (disposing && (components != null))
18 | {
19 | components.Dispose();
20 | }
21 | base.Dispose(disposing);
22 | }
23 |
24 | #region Component Designer generated code
25 |
26 | ///
27 | /// Required method for Designer support - do not modify
28 | /// the contents of this method with the code editor.
29 | ///
30 | private void InitializeComponent()
31 | {
32 | this.SuspendLayout();
33 | //
34 | // TransparentSimpleLogTextBox
35 | //
36 | this.Name = "TransparentSimpleLogTextBox";
37 | this.Size = new System.Drawing.Size(346, 82);
38 | this.ResumeLayout(false);
39 |
40 | }
41 |
42 | #endregion
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/src/Serilog.Sinks.WinForms.Core/TransparentSimpleLogTextBox.cs:
--------------------------------------------------------------------------------
1 | using System.ComponentModel;
2 | using Serilog.Sinks.WinForms.Base;
3 |
4 | namespace Serilog.Sinks.WinForms.Core
5 | {
6 | public partial class TransparentSimpleLogTextBox : TextBox
7 | {
8 | [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
9 | [Category("Serilog Sink WinForms")] public string ForContext { get; set; } = string.Empty;
10 |
11 | [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
12 | [Category("Serilog Sink WinForms")] public bool AutoPurge { get; set; }
13 |
14 | [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
15 | [Category("Serilog Sink WinForms")] public double AutoPurgeTime { get; set; } = 60;
16 |
17 | private bool _isContextConfigured = false;
18 | private System.Windows.Forms.Timer _timer;
19 |
20 | public TransparentSimpleLogTextBox()
21 | {
22 | InitializeComponent();
23 |
24 | SetStyle(ControlStyles.SupportsTransparentBackColor |
25 | ControlStyles.OptimizedDoubleBuffer |
26 | ControlStyles.AllPaintingInWmPaint |
27 | ControlStyles.ResizeRedraw |
28 | ControlStyles.UserPaint, true);
29 |
30 | BackColor = Color.Transparent;
31 | WindFormsSink.SimpleTextBoxSink.OnLogReceived += SimpleTextBoxSinkOnLogReceived;
32 |
33 | HandleDestroyed += (handler, args) =>
34 | {
35 | WindFormsSink.SimpleTextBoxSink.OnLogReceived -= SimpleTextBoxSinkOnLogReceived;
36 | };
37 |
38 | this.Multiline = true;
39 |
40 | if (AutoPurge)
41 | {
42 | _timer = new System.Windows.Forms.Timer
43 | {
44 | Interval = Convert.ToInt32(TimeSpan.FromMinutes(AutoPurgeTime).TotalMilliseconds)
45 | };
46 | _timer.Tick += _timer_Tick;
47 | _timer.Start();
48 | }
49 | }
50 |
51 | private void _timer_Tick(object sender, EventArgs e)
52 | {
53 | ClearLogs();
54 | }
55 |
56 | private void SimpleTextBoxSinkOnLogReceived(string context, string str)
57 | {
58 | if (_isContextConfigured)
59 | {
60 | if (!string.IsNullOrEmpty(this.ForContext)
61 | && !string.IsNullOrEmpty(context)
62 | && this.ForContext.Equals(context, StringComparison.InvariantCultureIgnoreCase)) { PrintLog(str); }
63 | }
64 | else
65 | {
66 | PrintLog(str);
67 | }
68 |
69 | Application.DoEvents();
70 | }
71 |
72 | private void PrintLog(string str)
73 | {
74 | if (this.InvokeRequired)
75 | {
76 | this.Invoke(
77 | (MethodInvoker)delegate
78 | {
79 | this.AppendText(str);
80 | this.ScrollToCaret();
81 | });
82 | }
83 | else
84 | {
85 | this.AppendText(str);
86 | this.ScrollToCaret();
87 | }
88 | }
89 |
90 | public void ClearLogs()
91 | {
92 | if (this.InvokeRequired)
93 | {
94 | this.Invoke((MethodInvoker)(() => this.Clear()));
95 | }
96 | else
97 | {
98 | this.Clear();
99 | }
100 | }
101 |
102 | public void SaveLogToFile()
103 | {
104 | SaveFileHelper.SaveLogsToFile(this.Text);
105 | }
106 | }
107 | }
--------------------------------------------------------------------------------
/src/Serilog.Sinks.WinForms.Net/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/src/Serilog.Sinks.WinForms.Net/GridLog.Designer.cs:
--------------------------------------------------------------------------------
1 | namespace Serilog.Sinks.WinForms
2 | {
3 | partial class GridLog
4 | {
5 | ///
6 | /// Required designer variable.
7 | ///
8 | private System.ComponentModel.IContainer components = null;
9 |
10 | ///
11 | /// Clean up any resources being used.
12 | ///
13 | /// true if managed resources should be disposed; otherwise, false.
14 | protected override void Dispose(bool disposing)
15 | {
16 | if (disposing && (components != null))
17 | {
18 | components.Dispose();
19 | }
20 | base.Dispose(disposing);
21 | }
22 |
23 | #region Component Designer generated code
24 |
25 | ///
26 | /// Required method for Designer support - do not modify
27 | /// the contents of this method with the code editor.
28 | ///
29 | private void InitializeComponent()
30 | {
31 | System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle();
32 | this.LogGridView = new System.Windows.Forms.DataGridView();
33 | this.TimeStamp = new System.Windows.Forms.DataGridViewTextBoxColumn();
34 | this.Level = new System.Windows.Forms.DataGridViewTextBoxColumn();
35 | this.Log = new System.Windows.Forms.DataGridViewTextBoxColumn();
36 | ((System.ComponentModel.ISupportInitialize)(this.LogGridView)).BeginInit();
37 | this.SuspendLayout();
38 | //
39 | // LogGridView
40 | //
41 | this.LogGridView.AllowUserToAddRows = false;
42 | this.LogGridView.AllowUserToDeleteRows = false;
43 | this.LogGridView.BackgroundColor = System.Drawing.SystemColors.Control;
44 | this.LogGridView.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
45 | this.LogGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
46 | this.LogGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
47 | this.TimeStamp,
48 | this.Level,
49 | this.Log});
50 | this.LogGridView.Dock = System.Windows.Forms.DockStyle.Fill;
51 | this.LogGridView.Location = new System.Drawing.Point(0, 0);
52 | this.LogGridView.Name = "LogGridView";
53 | this.LogGridView.ReadOnly = true;
54 | this.LogGridView.RowHeadersVisible = false;
55 | this.LogGridView.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.CellSelect;
56 | this.LogGridView.Size = new System.Drawing.Size(358, 150);
57 | this.LogGridView.TabIndex = 0;
58 | //
59 | // TimeStamp
60 | //
61 | this.TimeStamp.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
62 | this.TimeStamp.HeaderText = "TimeStamp";
63 | this.TimeStamp.Name = "TimeStamp";
64 | this.TimeStamp.ReadOnly = true;
65 | this.TimeStamp.Width = 85;
66 | //
67 | // Level
68 | //
69 | this.Level.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
70 | this.Level.HeaderText = "Level";
71 | this.Level.Name = "Level";
72 | this.Level.ReadOnly = true;
73 | this.Level.Width = 58;
74 | //
75 | // Log
76 | //
77 | this.Log.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
78 | dataGridViewCellStyle1.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
79 | this.Log.DefaultCellStyle = dataGridViewCellStyle1;
80 | this.Log.HeaderText = "Log";
81 | this.Log.Name = "Log";
82 | this.Log.ReadOnly = true;
83 | //
84 | // GridLog
85 | //
86 | this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
87 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
88 | this.Controls.Add(this.LogGridView);
89 | this.Name = "GridLog";
90 | this.Size = new System.Drawing.Size(358, 150);
91 | this.Load += new System.EventHandler(this.GridLog_Load);
92 | ((System.ComponentModel.ISupportInitialize)(this.LogGridView)).EndInit();
93 | this.ResumeLayout(false);
94 |
95 | }
96 |
97 | #endregion
98 |
99 | private System.Windows.Forms.DataGridView LogGridView;
100 | private System.Windows.Forms.DataGridViewTextBoxColumn TimeStamp;
101 | private System.Windows.Forms.DataGridViewTextBoxColumn Level;
102 | private System.Windows.Forms.DataGridViewTextBoxColumn Log;
103 | }
104 | }
105 |
--------------------------------------------------------------------------------
/src/Serilog.Sinks.WinForms.Net/GridLog.cs:
--------------------------------------------------------------------------------
1 | using Serilog.Sinks.WinForms.Base;
2 | using System;
3 | using System.Windows.Forms;
4 |
5 | namespace Serilog.Sinks.WinForms
6 | {
7 | public partial class GridLog : UserControl
8 | {
9 | public GridLog()
10 | {
11 | InitializeComponent();
12 | }
13 |
14 | private void GridLog_Load(object sender, EventArgs e)
15 | {
16 | LogGridView.Font = this.Font;
17 |
18 | WindFormsSink.GridLogSink.OnGridLogReceived += GridLogSink_OnGridLogReceived;
19 |
20 | HandleDestroyed += (handler, args) =>
21 | {
22 | WindFormsSink.GridLogSink.OnGridLogReceived -= GridLogSink_OnGridLogReceived;
23 | };
24 | }
25 |
26 | private void GridLogSink_OnGridLogReceived(GridLogEvent logEvent)
27 | {
28 | if (this.InvokeRequired)
29 | {
30 | this.Invoke(
31 | (MethodInvoker)delegate
32 | {
33 | LogGridView.Rows.Add(logEvent.TimeStamp.ToString(), logEvent.Level, logEvent.Message?.Trim());
34 | LogGridView.FirstDisplayedScrollingRowIndex = LogGridView.RowCount - 1;
35 | });
36 | }
37 | else
38 | {
39 | LogGridView.Rows.Add(logEvent.TimeStamp.ToString(), logEvent.Level, logEvent.Message);
40 | LogGridView.FirstDisplayedScrollingRowIndex = LogGridView.RowCount - 1;
41 | }
42 |
43 | Application.DoEvents();
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/src/Serilog.Sinks.WinForms.Net/ILLink/ILLink.Descriptors.LibraryBuild.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/src/Serilog.Sinks.WinForms.Net/JsonLogTextBox.Designer.cs:
--------------------------------------------------------------------------------
1 | namespace Serilog.Sinks.WinForms
2 | {
3 | partial class JsonLogTextBox
4 | {
5 | ///
6 | /// Required designer variable.
7 | ///
8 | private System.ComponentModel.IContainer components = null;
9 |
10 | ///
11 | /// Clean up any resources being used.
12 | ///
13 | /// true if managed resources should be disposed; otherwise, false.
14 | protected override void Dispose(bool disposing)
15 | {
16 | if (disposing && (components != null))
17 | {
18 | components.Dispose();
19 | }
20 | base.Dispose(disposing);
21 | }
22 |
23 | #region Component Designer generated code
24 |
25 | ///
26 | /// Required method for Designer support - do not modify
27 | /// the contents of this method with the code editor.
28 | ///
29 | private void InitializeComponent()
30 | {
31 | this.TxtLogControl = new System.Windows.Forms.TextBox();
32 | this.SuspendLayout();
33 | //
34 | // TxtLogControl
35 | //
36 | this.TxtLogControl.Dock = System.Windows.Forms.DockStyle.Fill;
37 | this.TxtLogControl.Location = new System.Drawing.Point(0, 0);
38 | this.TxtLogControl.Multiline = true;
39 | this.TxtLogControl.Name = "TxtLogControl";
40 | this.TxtLogControl.Size = new System.Drawing.Size(372, 158);
41 | this.TxtLogControl.TabIndex = 0;
42 | //
43 | // LogTextBox
44 | //
45 | this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
46 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
47 | this.Controls.Add(this.TxtLogControl);
48 | this.Name = "LogTextBox";
49 | this.Size = new System.Drawing.Size(372, 158);
50 | this.Load += new System.EventHandler(this.LogTextBox_Load);
51 | this.ResumeLayout(false);
52 | this.PerformLayout();
53 |
54 | }
55 |
56 | #endregion
57 |
58 | private System.Windows.Forms.TextBox TxtLogControl;
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/src/Serilog.Sinks.WinForms.Net/JsonLogTextBox.cs:
--------------------------------------------------------------------------------
1 | using Serilog.Sinks.WinForms.Base;
2 | using System;
3 | using System.Windows.Forms;
4 |
5 | namespace Serilog.Sinks.WinForms
6 | {
7 | public partial class JsonLogTextBox : UserControl
8 | {
9 | public ScrollBars ScrollBars { get; set; }
10 |
11 | public Padding LogPadding { get; set; } = new Padding(3, 3, 3, 3);
12 |
13 | public bool ReadOnly { get; set; }
14 |
15 | public BorderStyle LogBorderStyle { get; set; } = BorderStyle.Fixed3D;
16 |
17 | public string ForContext { get; set; } = string.Empty;
18 |
19 | private bool _isContextConfigured = false;
20 |
21 | public JsonLogTextBox()
22 | {
23 | InitializeComponent();
24 | }
25 |
26 | private void LogTextBox_Load(object sender, EventArgs e)
27 | {
28 | TxtLogControl.ScrollBars = ScrollBars;
29 | TxtLogControl.Padding = LogPadding;
30 | TxtLogControl.ReadOnly = ReadOnly;
31 | TxtLogControl.BorderStyle = LogBorderStyle;
32 | TxtLogControl.Font = this.Font;
33 | TxtLogControl.ForeColor = this.ForeColor;
34 | TxtLogControl.BackColor = this.BackColor;
35 | WindFormsSink.JsonTextBoxSink.OnLogReceived += JsonTextBoxSinkOnLogReceived;
36 |
37 | HandleDestroyed += ( handler, args ) =>
38 | {
39 | WindFormsSink.JsonTextBoxSink.OnLogReceived -= JsonTextBoxSinkOnLogReceived;
40 | };
41 | }
42 |
43 | private void JsonTextBoxSinkOnLogReceived(string context, string str)
44 | {
45 | if (_isContextConfigured)
46 | {
47 | if (!string.IsNullOrEmpty(this.ForContext)
48 | && !string.IsNullOrEmpty(context)
49 | && this.ForContext.Equals(context, StringComparison.InvariantCultureIgnoreCase)) { PrintText(str); }
50 | }
51 | else
52 | {
53 | PrintText(str);
54 | }
55 |
56 | Application.DoEvents();
57 | }
58 |
59 | private void PrintText(string str)
60 | {
61 | if (this.InvokeRequired)
62 | {
63 | this.Invoke(
64 | (MethodInvoker)delegate
65 | {
66 | TxtLogControl.AppendText(str);
67 | TxtLogControl.ScrollToCaret();
68 | });
69 | }
70 | else
71 | {
72 | TxtLogControl.AppendText(str);
73 | TxtLogControl.ScrollToCaret();
74 | }
75 | }
76 |
77 | public void ClearLogs()
78 | {
79 | if (this.InvokeRequired)
80 | {
81 | this.Invoke((MethodInvoker)(() => TxtLogControl.Clear()));
82 | }
83 | else
84 | {
85 | TxtLogControl.Clear();
86 | }
87 | }
88 |
89 | public void SaveLogToFile()
90 | {
91 | SaveFileHelper.SaveLogsToFile(TxtLogControl.Text);
92 | }
93 | }
94 | }
95 |
--------------------------------------------------------------------------------
/src/Serilog.Sinks.WinForms.Net/JsonLogTextBox.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 | text/microsoft-resx
110 |
111 |
112 | 2.0
113 |
114 |
115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
119 |
120 |
--------------------------------------------------------------------------------
/src/Serilog.Sinks.WinForms.Net/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Resources;
2 | using System.Reflection;
3 | using System.Runtime.CompilerServices;
4 | using System.Runtime.InteropServices;
5 |
6 | // General Information about an assembly is controlled through the following
7 | // set of attributes. Change these attribute values to modify the information
8 | // associated with an assembly.
9 | [assembly: AssemblyTitle("Serilog.Sinks.WinForms")]
10 | [assembly: AssemblyDescription("Writes Serilog events to Windows Forms Application TextBox or Datagridview control from anywhere in your application.")]
11 | [assembly: AssemblyConfiguration("")]
12 | [assembly: AssemblyCompany("umairsyed613")]
13 | [assembly: AssemblyProduct("Serilog.Sinks.WinForms")]
14 | [assembly: AssemblyCopyright("Copyright © 2022")]
15 | [assembly: AssemblyTrademark("")]
16 | [assembly: AssemblyCulture("")]
17 |
18 | // Setting ComVisible to false makes the types in this assembly not visible
19 | // to COM components. If you need to access a type in this assembly from
20 | // COM, set the ComVisible attribute to true on that type.
21 | [assembly: ComVisible(false)]
22 |
23 | // The following GUID is for the ID of the typelib if this project is exposed to COM
24 | [assembly: Guid("e6e8355a-dc58-45b7-bbd3-8132610f5ebf")]
25 |
26 | // Version information for an assembly consists of the following four values:
27 | //
28 | // Major Version
29 | // Minor Version
30 | // Build Number
31 | // Revision
32 | //
33 | // You can specify all the values or you can default the Build and Revision Numbers
34 | // by using the '*' as shown below:
35 | // [assembly: AssemblyVersion("1.0.*")]
36 | [assembly: AssemblyVersion("2.5.0.0")]
37 | [assembly: AssemblyFileVersion("2.5.0.0")]
38 | [assembly: NeutralResourcesLanguage("en")]
39 |
--------------------------------------------------------------------------------
/src/Serilog.Sinks.WinForms.Net/RichTextBoxLogControl.Designer.cs:
--------------------------------------------------------------------------------
1 |
2 | namespace Serilog.Sinks.WinForms
3 | {
4 | partial class RichTextBoxLogControl
5 | {
6 | ///
7 | /// Required designer variable.
8 | ///
9 | private System.ComponentModel.IContainer components = null;
10 |
11 | ///
12 | /// Clean up any resources being used.
13 | ///
14 | /// true if managed resources should be disposed; otherwise, false.
15 | protected override void Dispose(bool disposing)
16 | {
17 | if (disposing && (components != null))
18 | {
19 | components.Dispose();
20 | }
21 | base.Dispose(disposing);
22 | }
23 |
24 | #region Component Designer generated code
25 |
26 | ///
27 | /// Required method for Designer support - do not modify
28 | /// the contents of this method with the code editor.
29 | ///
30 | private void InitializeComponent()
31 | {
32 | components = new System.ComponentModel.Container();
33 | }
34 |
35 | #endregion
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/Serilog.Sinks.WinForms.Net/RichTextBoxLogControl.cs:
--------------------------------------------------------------------------------
1 | using Serilog.Sinks.WinForms.Base;
2 | using System;
3 | using System.ComponentModel;
4 | using System.Windows.Forms;
5 |
6 | namespace Serilog.Sinks.WinForms
7 | {
8 | public partial class RichTextBoxLogControl : RichTextBox
9 | {
10 | [Category("Serilog Sink WinForms")] public string ForContext { get; set; } = string.Empty;
11 | [Category("Serilog Sink WinForms")] public bool AutoPurge { get; set; }
12 | [Category("Serilog Sink WinForms")] public double AutoPurgeTime { get; set; } = 60;
13 |
14 | private Timer _timer;
15 |
16 | public RichTextBoxLogControl()
17 | {
18 | InitializeComponent();
19 |
20 | WindFormsSink.SimpleTextBoxSink.OnLogReceived += SimpleTextBoxSinkOnLogReceived;
21 |
22 | HandleDestroyed += ( sender, args ) =>
23 | {
24 | WindFormsSink.SimpleTextBoxSink.OnLogReceived -= SimpleTextBoxSinkOnLogReceived;
25 | };
26 |
27 | if (AutoPurge)
28 | {
29 | _timer = new Timer
30 | {
31 | Interval = Convert.ToInt32(TimeSpan.FromMinutes(AutoPurgeTime).TotalMilliseconds)
32 | };
33 | _timer.Tick += _timer_Tick;
34 | _timer.Start();
35 | }
36 | }
37 |
38 | private void _timer_Tick(object sender, EventArgs e)
39 | {
40 | ClearLogs();
41 | }
42 |
43 | private void SimpleTextBoxSinkOnLogReceived(string context, string str)
44 | {
45 | if (!string.IsNullOrEmpty(this.ForContext.Trim()))
46 | {
47 | if (!string.IsNullOrEmpty(context)
48 | && this.ForContext.Equals(context, StringComparison.InvariantCultureIgnoreCase)) { PrintText(str); }
49 | }
50 | else
51 | {
52 | PrintText(str);
53 | }
54 |
55 | Application.DoEvents();
56 | }
57 |
58 | private void PrintText(string str)
59 | {
60 | if (this.InvokeRequired)
61 | {
62 | this.Invoke((MethodInvoker) delegate
63 | {
64 | this.AppendText(str);
65 | this.ScrollToCaret();
66 | });
67 | }
68 | else
69 | {
70 | this.AppendText(str);
71 | this.ScrollToCaret();
72 | }
73 | }
74 |
75 | public void ClearLogs()
76 | {
77 | if (this.InvokeRequired)
78 | {
79 | this.Invoke((MethodInvoker)(() => this.Clear()));
80 | }
81 | else
82 | {
83 | this.Clear();
84 | }
85 | }
86 |
87 | public void SaveLogToFile()
88 | {
89 | SaveFileHelper.SaveLogsToFile(this.Text);
90 | }
91 | }
92 | }
93 |
--------------------------------------------------------------------------------
/src/Serilog.Sinks.WinForms.Net/SaveFileHelper.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IO;
3 | using System.Windows.Forms;
4 |
5 | namespace Serilog.Sinks.WinForms
6 | {
7 | public static class SaveFileHelper
8 | {
9 | internal static void SaveLogsToFile(string fileContent)
10 | {
11 | try
12 | {
13 | var saveFileDialog = new SaveFileDialog { Filter = @"Text Files | *.txt| Log Files |*.log" };
14 |
15 | if (saveFileDialog.ShowDialog() == DialogResult.OK)
16 | {
17 | File.AppendAllText(saveFileDialog.FileName, fileContent);
18 | }
19 | }
20 | catch (Exception e)
21 | {
22 | MessageBox.Show(e.Message, @"Error Saving Log File", MessageBoxButtons.OK, MessageBoxIcon.Error);
23 | }
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/Serilog.Sinks.WinForms.Net/Serilog.Sinks.WinForms.nuspec:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | $id$
5 | $version$
6 | Serilog.Sinks.WinForms
7 | UmairSyed (@umairsyed613)
8 | false
9 | MIT
10 | https://github.com/umairsyed613/Serilog.Sinks.WinForms
11 |
12 | Writes Serilog events to Windows Forms Application TextBox or Datagridview control from anywhere in your application.
13 | Read Docs at https://github.com/umairsyed613/Serilog.Sinks.WinForms
14 | $copyright$
15 | Serilog WindowsForms WinForm WinForms SerilogSink Sink Windows Forms Application
16 | images\icon.png
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/src/Serilog.Sinks.WinForms.Net/SimpleLogTextBox.Designer.cs:
--------------------------------------------------------------------------------
1 | namespace Serilog.Sinks.WinForms
2 | {
3 | partial class SimpleLogTextBox
4 | {
5 | ///
6 | /// Required designer variable.
7 | ///
8 | private System.ComponentModel.IContainer components = null;
9 |
10 | ///
11 | /// Clean up any resources being used.
12 | ///
13 | /// true if managed resources should be disposed; otherwise, false.
14 | protected override void Dispose(bool disposing)
15 | {
16 | if (disposing && (components != null))
17 | {
18 | components.Dispose();
19 | }
20 | base.Dispose(disposing);
21 | }
22 |
23 | #region Component Designer generated code
24 |
25 | ///
26 | /// Required method for Designer support - do not modify
27 | /// the contents of this method with the code editor.
28 | ///
29 | private void InitializeComponent()
30 | {
31 | this.TxtLogControl = new System.Windows.Forms.TextBox();
32 | this.SuspendLayout();
33 | //
34 | // TxtLogControl
35 | //
36 | this.TxtLogControl.Dock = System.Windows.Forms.DockStyle.Fill;
37 | this.TxtLogControl.Location = new System.Drawing.Point(0, 0);
38 | this.TxtLogControl.Multiline = true;
39 | this.TxtLogControl.Name = "TxtLogControl";
40 | this.TxtLogControl.Size = new System.Drawing.Size(372, 158);
41 | this.TxtLogControl.TabIndex = 0;
42 | //
43 | // LogTextBox
44 | //
45 | this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
46 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
47 | this.Controls.Add(this.TxtLogControl);
48 | this.Name = "LogTextBox";
49 | this.Size = new System.Drawing.Size(372, 158);
50 | this.Load += new System.EventHandler(this.LogTextBox_Load);
51 | this.ResumeLayout(false);
52 | this.PerformLayout();
53 |
54 | }
55 |
56 | #endregion
57 |
58 | private System.Windows.Forms.TextBox TxtLogControl;
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/src/Serilog.Sinks.WinForms.Net/SimpleLogTextBox.cs:
--------------------------------------------------------------------------------
1 | using Serilog.Sinks.WinForms.Base;
2 | using System;
3 | using System.ComponentModel;
4 | using System.Windows.Forms;
5 |
6 | namespace Serilog.Sinks.WinForms
7 | {
8 | public partial class SimpleLogTextBox : UserControl
9 | {
10 | private bool _isContextConfigured = false;
11 |
12 | [Category("Serilog Sink WinForms")] public ScrollBars ScrollBars { get; set; }
13 | [Category("Serilog Sink WinForms")] public Padding LogPadding { get; set; } = new Padding(3, 3, 3, 3);
14 | [Category("Serilog Sink WinForms")] public bool ReadOnly { get; set; }
15 | [Category("Serilog Sink WinForms")] public string ForContext { get; set; } = string.Empty;
16 | [Category("Serilog Sink WinForms")] public BorderStyle LogBorderStyle { get; set; } = BorderStyle.Fixed3D;
17 | [Category("Serilog Sink WinForms")] public bool AutoPurge { get; set; }
18 | [Category("Serilog Sink WinForms")] public double AutoPurgeTime { get; set; } = 60;
19 |
20 | private Timer _timer;
21 |
22 | public SimpleLogTextBox()
23 | {
24 | InitializeComponent();
25 | }
26 |
27 | private void LogTextBox_Load(object sender, EventArgs e)
28 | {
29 | TxtLogControl.ScrollBars = ScrollBars;
30 | TxtLogControl.Padding = LogPadding;
31 | TxtLogControl.ReadOnly = ReadOnly;
32 | TxtLogControl.BorderStyle = LogBorderStyle;
33 | TxtLogControl.Font = this.Font;
34 | TxtLogControl.ForeColor = this.ForeColor;
35 | TxtLogControl.BackColor = this.BackColor;
36 | _isContextConfigured = !string.IsNullOrEmpty(this.ForContext);
37 |
38 | WindFormsSink.SimpleTextBoxSink.OnLogReceived += SimpleTextBoxSinkOnLogReceived;
39 |
40 | HandleDestroyed += (handler, args) =>
41 | {
42 | WindFormsSink.SimpleTextBoxSink.OnLogReceived -= SimpleTextBoxSinkOnLogReceived;
43 | };
44 |
45 | if (AutoPurge)
46 | {
47 | _timer = new Timer
48 | {
49 | Interval = Convert.ToInt32(TimeSpan.FromMinutes(AutoPurgeTime).TotalMilliseconds)
50 | };
51 | _timer.Tick += _timer_Tick;
52 | _timer.Start();
53 | }
54 | }
55 |
56 | private void _timer_Tick(object sender, EventArgs e)
57 | {
58 | ClearLogs();
59 | }
60 |
61 | public void ClearLogs()
62 | {
63 | if (this.InvokeRequired)
64 | {
65 | this.Invoke((MethodInvoker)(() => TxtLogControl.Clear()));
66 | }
67 | else
68 | {
69 | TxtLogControl.Clear();
70 | }
71 | }
72 |
73 | private void SimpleTextBoxSinkOnLogReceived(string context, string str)
74 | {
75 | if (_isContextConfigured)
76 | {
77 | if (!string.IsNullOrEmpty(this.ForContext)
78 | && !string.IsNullOrEmpty(context)
79 | && this.ForContext.Equals(context, StringComparison.InvariantCultureIgnoreCase))
80 | {
81 | PrintText(str);
82 | }
83 | }
84 | else
85 | {
86 | PrintText(str);
87 | }
88 |
89 | Application.DoEvents();
90 | }
91 |
92 | private void PrintText(string str)
93 | {
94 | if (this.InvokeRequired)
95 | {
96 | this.Invoke(
97 | (MethodInvoker)delegate
98 | {
99 | TxtLogControl.AppendText(str);
100 | TxtLogControl.ScrollToCaret();
101 | });
102 | }
103 | else
104 | {
105 | TxtLogControl.AppendText(str);
106 | TxtLogControl.ScrollToCaret();
107 | }
108 | }
109 |
110 |
111 | public void SaveLogToFile()
112 | {
113 | SaveFileHelper.SaveLogsToFile(TxtLogControl.Text);
114 | }
115 | }
116 | }
--------------------------------------------------------------------------------
/src/Serilog.Sinks.WinForms.Net/TransparentSimpleLogTextBox.Designer.cs:
--------------------------------------------------------------------------------
1 |
2 | namespace Serilog.Sinks.WinForms
3 | {
4 | partial class TransparentSimpleLogTextBox
5 | {
6 | ///
7 | /// Required designer variable.
8 | ///
9 | private System.ComponentModel.IContainer components = null;
10 |
11 | ///
12 | /// Clean up any resources being used.
13 | ///
14 | /// true if managed resources should be disposed; otherwise, false.
15 | protected override void Dispose(bool disposing)
16 | {
17 | if (disposing && (components != null))
18 | {
19 | components.Dispose();
20 | }
21 | base.Dispose(disposing);
22 | }
23 |
24 | #region Component Designer generated code
25 |
26 | ///
27 | /// Required method for Designer support - do not modify
28 | /// the contents of this method with the code editor.
29 | ///
30 | private void InitializeComponent()
31 | {
32 | this.SuspendLayout();
33 | //
34 | // TransparentSimpleLogTextBox
35 | //
36 | this.Name = "TransparentSimpleLogTextBox";
37 | this.Size = new System.Drawing.Size(346, 82);
38 | this.ResumeLayout(false);
39 |
40 | }
41 |
42 | #endregion
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/src/Serilog.Sinks.WinForms.Net/TransparentSimpleLogTextBox.cs:
--------------------------------------------------------------------------------
1 | using Serilog.Sinks.WinForms.Base;
2 | using System;
3 | using System.ComponentModel;
4 | using System.Drawing;
5 | using System.Windows.Forms;
6 |
7 | namespace Serilog.Sinks.WinForms
8 | {
9 | public partial class TransparentSimpleLogTextBox : TextBox
10 | {
11 | [Category("Serilog Sink WinForms")] public string ForContext { get; set; } = string.Empty;
12 | [Category("Serilog Sink WinForms")] public bool AutoPurge { get; set; }
13 | [Category("Serilog Sink WinForms")] public double AutoPurgeTime { get; set; } = 60;
14 |
15 | private bool _isContextConfigured = false;
16 | private Timer _timer;
17 |
18 | public TransparentSimpleLogTextBox()
19 | {
20 | InitializeComponent();
21 |
22 | SetStyle(ControlStyles.SupportsTransparentBackColor |
23 | ControlStyles.OptimizedDoubleBuffer |
24 | ControlStyles.AllPaintingInWmPaint |
25 | ControlStyles.ResizeRedraw |
26 | ControlStyles.UserPaint, true);
27 |
28 | BackColor = Color.Transparent;
29 | WindFormsSink.SimpleTextBoxSink.OnLogReceived += SimpleTextBoxSinkOnLogReceived;
30 |
31 | HandleDestroyed += ( handler, args ) =>
32 | {
33 | WindFormsSink.SimpleTextBoxSink.OnLogReceived -= SimpleTextBoxSinkOnLogReceived;
34 | };
35 |
36 | this.Multiline = true;
37 |
38 | if (AutoPurge)
39 | {
40 | _timer = new Timer
41 | {
42 | Interval = Convert.ToInt32(TimeSpan.FromMinutes(AutoPurgeTime).TotalMilliseconds)
43 | };
44 | _timer.Tick += _timer_Tick;
45 | _timer.Start();
46 | }
47 | }
48 |
49 | private void _timer_Tick(object sender, EventArgs e)
50 | {
51 | ClearLogs();
52 | }
53 |
54 | private void SimpleTextBoxSinkOnLogReceived(string context, string str)
55 | {
56 | if (_isContextConfigured)
57 | {
58 | if (!string.IsNullOrEmpty(this.ForContext)
59 | && !string.IsNullOrEmpty(context)
60 | && this.ForContext.Equals(context, StringComparison.InvariantCultureIgnoreCase)) { PrintLog(str); }
61 | }
62 | else
63 | {
64 | PrintLog(str);
65 | }
66 |
67 | Application.DoEvents();
68 | }
69 |
70 | private void PrintLog(string str)
71 | {
72 | if (this.InvokeRequired)
73 | {
74 | this.Invoke(
75 | (MethodInvoker) delegate
76 | {
77 | this.AppendText(str);
78 | this.ScrollToCaret();
79 | });
80 | }
81 | else
82 | {
83 | this.AppendText(str);
84 | this.ScrollToCaret();
85 | }
86 | }
87 |
88 | public void ClearLogs()
89 | {
90 | if (this.InvokeRequired)
91 | {
92 | this.Invoke((MethodInvoker)(() => this.Clear()));
93 | }
94 | else
95 | {
96 | this.Clear();
97 | }
98 | }
99 |
100 | public void SaveLogToFile()
101 | {
102 | SaveFileHelper.SaveLogsToFile(this.Text);
103 | }
104 | }
105 | }
106 |
--------------------------------------------------------------------------------
/src/Serilog.Sinks.WinForms.Net/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/src/Serilog.Sinks.WinForms.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 17
4 | VisualStudioVersion = 17.1.32210.238
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Serilog.Sinks.WinForms", "Serilog.Sinks.WinForms.Net\Serilog.Sinks.WinForms.csproj", "{E6E8355A-DC58-45B7-BBD3-8132610F5EBF}"
7 | EndProject
8 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Sample", "Sample", "{6FCBC6FF-1028-4DFA-8E0E-F5FC33A915CC}"
9 | EndProject
10 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestApplication", "Sample\TestApplication\TestApplication.csproj", "{9128AF8C-2E4B-486E-AEF2-F48DE2F61B09}"
11 | EndProject
12 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestApplicationWithTransparentBackground", "Sample\TestApplicationWithTransparentBackground\TestApplicationWithTransparentBackground.csproj", "{65D7C21E-45EC-46D3-B489-9CC20EFFF13F}"
13 | EndProject
14 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CustomSimpleTextLog", "Sample\CustomSimpleTextLog\CustomSimpleTextLog.csproj", "{151559CF-E59E-4CC1-8CDB-FF56882F9035}"
15 | EndProject
16 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Serilog.Sinks.WinForms.Core", "Serilog.Sinks.WinForms.Core\Serilog.Sinks.WinForms.Core.csproj", "{B1CC4152-652E-42FE-87D3-E9BC5AC5BB7C}"
17 | EndProject
18 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Serilog.Sinks.WinForms.Base", "Serilog.Sinks.WinForms.Base\Serilog.Sinks.WinForms.Base.csproj", "{CCB237EE-BC54-435F-A0F2-0C13CBCF6E06}"
19 | EndProject
20 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestApplicationNet9", "Sample\TestApplicationNet6\TestApplicationNet9.csproj", "{13CBCDA2-8B30-4F01-AAB1-6D749DD77B67}"
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 | {E6E8355A-DC58-45B7-BBD3-8132610F5EBF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
29 | {E6E8355A-DC58-45B7-BBD3-8132610F5EBF}.Debug|Any CPU.Build.0 = Debug|Any CPU
30 | {E6E8355A-DC58-45B7-BBD3-8132610F5EBF}.Release|Any CPU.ActiveCfg = Release|Any CPU
31 | {E6E8355A-DC58-45B7-BBD3-8132610F5EBF}.Release|Any CPU.Build.0 = Release|Any CPU
32 | {9128AF8C-2E4B-486E-AEF2-F48DE2F61B09}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
33 | {9128AF8C-2E4B-486E-AEF2-F48DE2F61B09}.Debug|Any CPU.Build.0 = Debug|Any CPU
34 | {9128AF8C-2E4B-486E-AEF2-F48DE2F61B09}.Release|Any CPU.ActiveCfg = Release|Any CPU
35 | {9128AF8C-2E4B-486E-AEF2-F48DE2F61B09}.Release|Any CPU.Build.0 = Release|Any CPU
36 | {65D7C21E-45EC-46D3-B489-9CC20EFFF13F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
37 | {65D7C21E-45EC-46D3-B489-9CC20EFFF13F}.Debug|Any CPU.Build.0 = Debug|Any CPU
38 | {65D7C21E-45EC-46D3-B489-9CC20EFFF13F}.Release|Any CPU.ActiveCfg = Release|Any CPU
39 | {65D7C21E-45EC-46D3-B489-9CC20EFFF13F}.Release|Any CPU.Build.0 = Release|Any CPU
40 | {151559CF-E59E-4CC1-8CDB-FF56882F9035}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
41 | {151559CF-E59E-4CC1-8CDB-FF56882F9035}.Debug|Any CPU.Build.0 = Debug|Any CPU
42 | {151559CF-E59E-4CC1-8CDB-FF56882F9035}.Release|Any CPU.ActiveCfg = Release|Any CPU
43 | {151559CF-E59E-4CC1-8CDB-FF56882F9035}.Release|Any CPU.Build.0 = Release|Any CPU
44 | {B1CC4152-652E-42FE-87D3-E9BC5AC5BB7C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
45 | {B1CC4152-652E-42FE-87D3-E9BC5AC5BB7C}.Debug|Any CPU.Build.0 = Debug|Any CPU
46 | {B1CC4152-652E-42FE-87D3-E9BC5AC5BB7C}.Release|Any CPU.ActiveCfg = Release|Any CPU
47 | {B1CC4152-652E-42FE-87D3-E9BC5AC5BB7C}.Release|Any CPU.Build.0 = Release|Any CPU
48 | {CCB237EE-BC54-435F-A0F2-0C13CBCF6E06}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
49 | {CCB237EE-BC54-435F-A0F2-0C13CBCF6E06}.Debug|Any CPU.Build.0 = Debug|Any CPU
50 | {CCB237EE-BC54-435F-A0F2-0C13CBCF6E06}.Release|Any CPU.ActiveCfg = Release|Any CPU
51 | {CCB237EE-BC54-435F-A0F2-0C13CBCF6E06}.Release|Any CPU.Build.0 = Release|Any CPU
52 | {13CBCDA2-8B30-4F01-AAB1-6D749DD77B67}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
53 | {13CBCDA2-8B30-4F01-AAB1-6D749DD77B67}.Debug|Any CPU.Build.0 = Debug|Any CPU
54 | {13CBCDA2-8B30-4F01-AAB1-6D749DD77B67}.Release|Any CPU.ActiveCfg = Release|Any CPU
55 | {13CBCDA2-8B30-4F01-AAB1-6D749DD77B67}.Release|Any CPU.Build.0 = Release|Any CPU
56 | EndGlobalSection
57 | GlobalSection(SolutionProperties) = preSolution
58 | HideSolutionNode = FALSE
59 | EndGlobalSection
60 | GlobalSection(NestedProjects) = preSolution
61 | {9128AF8C-2E4B-486E-AEF2-F48DE2F61B09} = {6FCBC6FF-1028-4DFA-8E0E-F5FC33A915CC}
62 | {65D7C21E-45EC-46D3-B489-9CC20EFFF13F} = {6FCBC6FF-1028-4DFA-8E0E-F5FC33A915CC}
63 | {151559CF-E59E-4CC1-8CDB-FF56882F9035} = {6FCBC6FF-1028-4DFA-8E0E-F5FC33A915CC}
64 | {13CBCDA2-8B30-4F01-AAB1-6D749DD77B67} = {6FCBC6FF-1028-4DFA-8E0E-F5FC33A915CC}
65 | EndGlobalSection
66 | GlobalSection(ExtensibilityGlobals) = postSolution
67 | SolutionGuid = {0A92E9B0-A616-4F29-AA90-DD1EC0F0BF60}
68 | EndGlobalSection
69 | EndGlobal
70 |
--------------------------------------------------------------------------------
/src/release.ps1:
--------------------------------------------------------------------------------
1 | nuget pack Serilog.Sinks.WinForms.Net/Serilog.Sinks.WinForms.csproj -Prop Configuration=Release
2 | nuget pack Serilog.Sinks.WinForms.Core/Serilog.Sinks.WinForms.Core.csproj -Prop Configuration=Release
--------------------------------------------------------------------------------