Comments (16)
Have you tried to explicit include the Assembly in your NLog.config
:
<nlog>
<extensions>
<add assembly="NLog.Windows.Forms"/>
</extensions>
from nlog.windows.forms.
Hi,
Could you please try this?
from nlog.windows.forms.
I added this one code line
NLog.LogManager.Setup().SetupExtensions(s =>s.RegisterAssembly("MyAssembly"));
at the very beginning of the program.cs main method and exchanged 'MyAssembly' with my Assembly name.
However this did not work. It still does not log into the corresponding richtext box when the program is published as single file.
from nlog.windows.forms.
Maybe try this:
NLog.LogManager.Setup().SetupExtensions(s => s.RegisterAssembly(typeof(NLog.Windows.Forms.RichTextBoxTarget).Assembly));
from nlog.windows.forms.
yes, this works.
However we have 20 Projects and try to keep it as 'tidy' as possible. In case it would be possible to fix the issue within the future version of nlog windows forms library, it would be great.
System.Configuration.ConfigurationManager had a similiar problem and fixed it with version 6.0.0 btw.
from nlog.windows.forms.
from nlog.windows.forms.
No, my nlog.config does not include any extension entries.
You can replace the explict RegisterAssembly
in source-code with <extensions>
-section in NLog.config.
Notice NLog 5.0 will no longer scan and load NLog-extension-assemblies automatically. Instead NLog-extension-assemblies must always be explicitly specified. But NLog 5.0 also introduces support for specifying assembly-name in target-type:
<target xsi:type="RichTextBox, NLog.Windows.Forms" name="myRichTextBox" ... />
from nlog.windows.forms.
Have you tried to explicit include the Assembly in your
NLog.config
:<nlog> <extensions> <add assembly="NLog.Windows.Forms"/> </extensions>
Thank you this also works. (So no code changes aka 'RegisterAssembly' necessary.)
from nlog.windows.forms.
You can replace the explict
RegisterAssembly
in source-code with<extensions>
-section in NLog.config.Notice NLog 5.0 will no longer scan and load NLog-extension-assemblies automatically. Instead NLog-extension-assemblies must always be explicitly specified. But NLog 5.0 also introduces support for specifying assembly-name in target-type:
<target xsi:type="RichTextBox, NLog.Windows.Forms" name="myRichTextBox" ... />
Adding
<target xsi:type="RichTextBox, NLog.Windows.Forms" name="myRichTextBox" ... />
was not sufficient (/ is not needed) when publishing as single file.
There also needs to be this declaration:
<extensions> <add assembly="NLog.Windows.Forms"/> </extensions>
(Tested with 5.0.0-rc2)
from nlog.windows.forms.
NLog InternalLogger looks like this on my machine, and it just works with NLog 5.0-RC2:
Info Message Template Auto Format enabled
Debug ScanAssembly('NLog, Version=5.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c')
Info Loading assembly: NLog.Windows.Forms
Debug ScanAssembly('NLog.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c')
If I just use xsi:type="RichTextBox"
then it fails like you experience.
from nlog.windows.forms.
This thread is all about publishing as single file.
Did you publish your application as Single file?
from nlog.windows.forms.
This is my csproj-file:
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0-windows</TargetFramework>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<UseWindowsForms>true</UseWindowsForms>
<PublishSingleFile>true</PublishSingleFile>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="NLog" Version="5.0.0-rc2" />
</ItemGroup>
And this is the command that I was running to perform the publish:
dotnet publish -c Release
This is the publish-folder:
This is the NLog.config:
<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.nlog-project.org/schemas/NLog.xsd NLog.xsd">
<targets>
<target xsi:type="RichTextBox, NLog.Windows.Forms"
name="target1"
layout="${message}"
autoScroll="true"
maxLines="30"
useDefaultRowColoringRules="true" />
from nlog.windows.forms.
Thanks,
I was just asking because the program behaviour differs in comparison to our application.
we also build with
dotnet publish -c:Release
However we have: (Net5.0)
<TargetFramework>net5.0-windows</TargetFramework>
and also usually
<IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract>
Perhaps that's where the different behaviour comes from.
As
<target xsi:type="RichTextBox, NLog.Windows.Forms" ... />
doesn't work for us.
Your answer:
Have you tried to explicit include the Assembly in your
NLog.config
:<nlog> <extensions> <add assembly="NLog.Windows.Forms"/> </extensions>
is already our solution and solves the problem on our side.
from nlog.windows.forms.
In your Testsetting I realized you are not using a controlName. Do you log into a separate Logging Window?
We are logging into an existing richtextbox, which is a big difference ...
`
<target name="locatortextbox" xsi:type="RichTextBox" controlName="locatorTextBox" formName="LogForm" maxLines="100" autoScroll="true"
useDefaultRowColoringRules="true" layout="${longdate} ${uppercase:${level}} ${message}" allowAccessoryFormCreation="False"/>
...
`
(Net5 <-> Net6 didnt make any difference)
<IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract>
also didnt make any difference.
from nlog.windows.forms.
Think your questions are beyond my skill-set when it comes to the NLog.Windows.Forms
-package.
I was mostly interested in whether xsi:type="RichTextBox, NLog.Windows.Forms"
worked with NLog 5.0 and PublishSingleFile=true (And it did for me).
And yes when using NLog 4.7 with PublishSingleFile=true
, then it will only work with:
<nlog>
<extensions>
<add assembly="NLog.Windows.Forms"/>
</extensions>
from nlog.windows.forms.
Closing issue as answered due to inactivity
from nlog.windows.forms.
Related Issues (20)
- net6.0-windows
- Support Layoutable properties HOT 3
- Fix default layout comments
- Breaking changes version 5
- Change AssemblyVersion to 5.0.0.0
- Using Only NLog.config for RichTextBox Does Not Log HOT 3
- Add net6.0-windows since LTS
- Continuous Build not running on merge to master HOT 1
- NullReferenceException in RichTextBoxTarget SendTheMessageToRichTextBox
- NLog.LogManager.Configuration reload causes RichTextBoxTarget to create a new form HOT 6
- Question: Is it possible to write to winforms ListView? HOT 2
- Form hanging when RichTextBox target nonstop logging HOT 6
- Symbols package publishing failed. HOT 1
- System.NullReferenceException calling ReInitializeAllTextboxes() HOT 5
- Missing source package on NuGet HOT 4
- RichTextBoxTarget - An exception occurred under NET48 HOT 3
- Create a nuget package with net5.0-windows platform supporting HOT 3
- No RowColor for RichTextBoxTarget when LeftToRight.Yes set HOT 3
- When to support net6.0 platform? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nlog.windows.forms.