Skip to content

Commit bd50e8d

Browse files
Fr33danJTignor
andauthored
Added examples (#95)
* Add ToolStripItemTarget. * Switch to using layout instead of strings Also move logic directly to write method rather than add a billion arguments to FindItemAndSendTheMessage * Add unit tests for ToolStripMenuItemTarget. * Do events so invoke can apply. Dispose form. * Add whitespace for clarity. Test dumb theory. * Add second DoEvents to make test pass because ??? * Run form on STA thread. * Read item only from form thread. * Add ability to track pending invocations for tests * Bring back the form threading. * Fix unit testing Use collections so tests don't run simultaneously as well as remove tricky code that didn't work and is just clutter if unneeded. * Simplify test further. * Pull examples from main project, add ToolStripItem * Update examples Bring example screenshot and config files into respective projects. Document in the code how code is equivalent to matching NLog.config. Take new screenshots (some were still from WinXP!) * Update readme with new target. Co-authored-by: JTignor <[email protected]>
1 parent 7b61b33 commit bd50e8d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+3251
-0
lines changed

Examples/FormControl/Example.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System;
2+
using System.Windows.Forms;
3+
using NLog;
4+
using NLog.Targets;
5+
6+
namespace RichTextBox2
7+
{
8+
static class Example
9+
{
10+
/// <summary>
11+
/// The main entry point for the application.
12+
/// </summary>
13+
[STAThread]
14+
static void Main()
15+
{
16+
Application.EnableVisualStyles();
17+
Application.SetCompatibleTextRenderingDefault(false);
18+
Application.Run(new Form1());
19+
// for NLog configuration look in Form1.cs
20+
}
21+
}
22+
}

Examples/FormControl/Form1.Designer.cs

Lines changed: 62 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Examples/FormControl/Form1.cs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using System;
2+
using System.Text;
3+
using System.Windows.Forms;
4+
using NLog;
5+
using NLog.Windows.Forms;
6+
7+
namespace RichTextBox2
8+
{
9+
public partial class Form1 : Form
10+
{
11+
public Form1()
12+
{
13+
InitializeComponent();
14+
}
15+
16+
private void Form1_Load(object sender, EventArgs e)
17+
{
18+
// Programmatic configuration that is equivalent to
19+
// the "control" target configuration in NLog.config
20+
FormControlTarget target = new FormControlTarget();
21+
target.Layout = "${date:format=HH\\:MM\\:ss} ${logger} ${message}";
22+
target.ControlName = "textBox1";
23+
target.FormName = "Form1";
24+
target.Append = true;
25+
26+
NLog.Config.SimpleConfigurator.ConfigureForTargetLogging(target, LogLevel.Trace);
27+
28+
Logger logger = LogManager.GetLogger("Example");
29+
logger.Trace("trace log message, ");
30+
logger.Debug("debug log message, ");
31+
logger.Info("info log message, ");
32+
logger.Warn("warn log message, ");
33+
logger.Error("error log message, ");
34+
logger.Fatal("fatal log message");
35+
}
36+
}
37+
}

Examples/FormControl/Form1.resx

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<root>
3+
<!--
4+
Microsoft ResX Schema
5+
6+
Version 2.0
7+
8+
The primary goals of this format is to allow a simple XML format
9+
that is mostly human readable. The generation and parsing of the
10+
various data types are done through the TypeConverter classes
11+
associated with the data types.
12+
13+
Example:
14+
15+
... ado.net/XML headers & schema ...
16+
<resheader name="resmimetype">text/microsoft-resx</resheader>
17+
<resheader name="version">2.0</resheader>
18+
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
19+
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
20+
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
21+
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
22+
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
23+
<value>[base64 mime encoded serialized .NET Framework object]</value>
24+
</data>
25+
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
26+
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
27+
<comment>This is a comment</comment>
28+
</data>
29+
30+
There are any number of "resheader" rows that contain simple
31+
name/value pairs.
32+
33+
Each data row contains a name, and value. The row also contains a
34+
type or mimetype. Type corresponds to a .NET class that support
35+
text/value conversion through the TypeConverter architecture.
36+
Classes that don't support this are serialized and stored with the
37+
mimetype set.
38+
39+
The mimetype is used for serialized objects, and tells the
40+
ResXResourceReader how to depersist the object. This is currently not
41+
extensible. For a given mimetype the value must be set accordingly:
42+
43+
Note - application/x-microsoft.net.object.binary.base64 is the format
44+
that the ResXResourceWriter will generate, however the reader can
45+
read any of the formats listed below.
46+
47+
mimetype: application/x-microsoft.net.object.binary.base64
48+
value : The object must be serialized with
49+
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
50+
: and then encoded with base64 encoding.
51+
52+
mimetype: application/x-microsoft.net.object.soap.base64
53+
value : The object must be serialized with
54+
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
55+
: and then encoded with base64 encoding.
56+
57+
mimetype: application/x-microsoft.net.object.bytearray.base64
58+
value : The object must be serialized into a byte array
59+
: using a System.ComponentModel.TypeConverter
60+
: and then encoded with base64 encoding.
61+
-->
62+
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
63+
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
64+
<xsd:element name="root" msdata:IsDataSet="true">
65+
<xsd:complexType>
66+
<xsd:choice maxOccurs="unbounded">
67+
<xsd:element name="metadata">
68+
<xsd:complexType>
69+
<xsd:sequence>
70+
<xsd:element name="value" type="xsd:string" minOccurs="0" />
71+
</xsd:sequence>
72+
<xsd:attribute name="name" use="required" type="xsd:string" />
73+
<xsd:attribute name="type" type="xsd:string" />
74+
<xsd:attribute name="mimetype" type="xsd:string" />
75+
<xsd:attribute ref="xml:space" />
76+
</xsd:complexType>
77+
</xsd:element>
78+
<xsd:element name="assembly">
79+
<xsd:complexType>
80+
<xsd:attribute name="alias" type="xsd:string" />
81+
<xsd:attribute name="name" type="xsd:string" />
82+
</xsd:complexType>
83+
</xsd:element>
84+
<xsd:element name="data">
85+
<xsd:complexType>
86+
<xsd:sequence>
87+
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
88+
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
89+
</xsd:sequence>
90+
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
91+
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
92+
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
93+
<xsd:attribute ref="xml:space" />
94+
</xsd:complexType>
95+
</xsd:element>
96+
<xsd:element name="resheader">
97+
<xsd:complexType>
98+
<xsd:sequence>
99+
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
100+
</xsd:sequence>
101+
<xsd:attribute name="name" type="xsd:string" use="required" />
102+
</xsd:complexType>
103+
</xsd:element>
104+
</xsd:choice>
105+
</xsd:complexType>
106+
</xsd:element>
107+
</xsd:schema>
108+
<resheader name="resmimetype">
109+
<value>text/microsoft-resx</value>
110+
</resheader>
111+
<resheader name="version">
112+
<value>2.0</value>
113+
</resheader>
114+
<resheader name="reader">
115+
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
116+
</resheader>
117+
<resheader name="writer">
118+
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
119+
</resheader>
120+
</root>
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="Current">
2+
<PropertyGroup>
3+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
4+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
5+
<ProductVersion>9.0.21022</ProductVersion>
6+
<SchemaVersion>2.0</SchemaVersion>
7+
<ProjectGuid>{20449142-40C3-4B1D-8F7C-2D3ED924FDA7}</ProjectGuid>
8+
<OutputType>WinExe</OutputType>
9+
<AppDesignerFolder>Properties</AppDesignerFolder>
10+
<RootNamespace>RichTextBox</RootNamespace>
11+
<AssemblyName>RichTextBox</AssemblyName>
12+
<FileUpgradeFlags>
13+
</FileUpgradeFlags>
14+
<UpgradeBackupLocation>
15+
</UpgradeBackupLocation>
16+
<OldToolsVersion>3.5</OldToolsVersion>
17+
</PropertyGroup>
18+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
19+
<DebugSymbols>true</DebugSymbols>
20+
<DebugType>full</DebugType>
21+
<Optimize>false</Optimize>
22+
<OutputPath>bin\Debug\</OutputPath>
23+
<DefineConstants>DEBUG;TRACE</DefineConstants>
24+
<ErrorReport>prompt</ErrorReport>
25+
<WarningLevel>4</WarningLevel>
26+
</PropertyGroup>
27+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
28+
<DebugType>pdbonly</DebugType>
29+
<Optimize>true</Optimize>
30+
<OutputPath>bin\Release\</OutputPath>
31+
<DefineConstants>TRACE</DefineConstants>
32+
<ErrorReport>prompt</ErrorReport>
33+
<WarningLevel>4</WarningLevel>
34+
</PropertyGroup>
35+
<ItemGroup>
36+
<Reference Include="NLog">
37+
<HintPath>..\..\NLog.Windows.Forms\bin\Debug\net35\NLog.dll</HintPath>
38+
</Reference>
39+
<Reference Include="NLog.Windows.Forms">
40+
<HintPath>..\..\NLog.Windows.Forms\bin\Debug\net35\NLog.Windows.Forms.dll</HintPath>
41+
</Reference>
42+
<Reference Include="System" />
43+
<Reference Include="System.Data" />
44+
<Reference Include="System.Drawing" />
45+
<Reference Include="System.Windows.Forms" />
46+
<Reference Include="System.Xml" />
47+
</ItemGroup>
48+
<ItemGroup>
49+
<Compile Include="Form1.cs">
50+
<SubType>Form</SubType>
51+
</Compile>
52+
<Compile Include="Form1.Designer.cs">
53+
<DependentUpon>Form1.cs</DependentUpon>
54+
</Compile>
55+
<Compile Include="Example.cs" />
56+
<Compile Include="Properties\AssemblyInfo.cs" />
57+
<EmbeddedResource Include="Form1.resx">
58+
<SubType>Designer</SubType>
59+
<DependentUpon>Form1.cs</DependentUpon>
60+
</EmbeddedResource>
61+
<EmbeddedResource Include="Properties\Resources.resx">
62+
<Generator>ResXFileCodeGenerator</Generator>
63+
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
64+
<SubType>Designer</SubType>
65+
</EmbeddedResource>
66+
<Compile Include="Properties\Resources.Designer.cs">
67+
<AutoGen>True</AutoGen>
68+
<DependentUpon>Resources.resx</DependentUpon>
69+
<DesignTime>True</DesignTime>
70+
</Compile>
71+
<None Include="NLog.config" />
72+
<None Include="Properties\Settings.settings">
73+
<Generator>SettingsSingleFileGenerator</Generator>
74+
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
75+
</None>
76+
<Compile Include="Properties\Settings.Designer.cs">
77+
<AutoGen>True</AutoGen>
78+
<DependentUpon>Settings.settings</DependentUpon>
79+
<DesignTimeSharedInput>True</DesignTimeSharedInput>
80+
</Compile>
81+
</ItemGroup>
82+
<ItemGroup>
83+
<Content Include="Results Screenshot.gif" />
84+
</ItemGroup>
85+
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
86+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
87+
Other similar extension points exist, see Microsoft.Common.targets.
88+
<Target Name="BeforeBuild">
89+
</Target>
90+
<Target Name="AfterBuild">
91+
</Target>
92+
-->
93+
</Project>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.31729.503
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FormControl", "FormControl.csproj", "{20449142-40C3-4B1D-8F7C-2D3ED924FDA7}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{20449142-40C3-4B1D-8F7C-2D3ED924FDA7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{20449142-40C3-4B1D-8F7C-2D3ED924FDA7}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{20449142-40C3-4B1D-8F7C-2D3ED924FDA7}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{20449142-40C3-4B1D-8F7C-2D3ED924FDA7}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {EECF1C6C-7358-4B7B-8E3D-C325FE63C9D6}
24+
EndGlobalSection
25+
EndGlobal

Examples/FormControl/NLog.config

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
4+
5+
<targets>
6+
<target name="control" xsi:type="FormControl" append="true" controlName="textBox1" formName="Form1" />
7+
</targets>
8+
9+
<rules>
10+
<logger name="*" minlevel="Debug" writeTo="control" />
11+
</rules>
12+
</nlog>

0 commit comments

Comments
 (0)