Giter Site home page Giter Site logo

Comments (16)

snakefoot avatar snakefoot commented on July 2, 2024 1

Have you tried to explicit include the Assembly in your NLog.config:

<nlog> 
  <extensions> 
    <add assembly="NLog.Windows.Forms"/> 
  </extensions> 

from nlog.windows.forms.

304NotModified avatar 304NotModified commented on July 2, 2024

Hi,

Could you please try this?

https://github.com/nlog/nlog/wiki/Register-your-custom-component#register-nlog-extensions-from-assembly-at-runtime

from nlog.windows.forms.

lionengine123 avatar lionengine123 commented on July 2, 2024

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.

snakefoot avatar snakefoot commented on July 2, 2024

Maybe try this:

NLog.LogManager.Setup().SetupExtensions(s => s.RegisterAssembly(typeof(NLog.Windows.Forms.RichTextBoxTarget).Assembly));

from nlog.windows.forms.

lionengine123 avatar lionengine123 commented on July 2, 2024

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.

lionengine123 avatar lionengine123 commented on July 2, 2024

from nlog.windows.forms.

snakefoot avatar snakefoot commented on July 2, 2024

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.

lionengine123 avatar lionengine123 commented on July 2, 2024

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.

lionengine123 avatar lionengine123 commented on July 2, 2024

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.

snakefoot avatar snakefoot commented on July 2, 2024

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.

lionengine123 avatar lionengine123 commented on July 2, 2024

This thread is all about publishing as single file.
Did you publish your application as Single file?

from nlog.windows.forms.

snakefoot avatar snakefoot commented on July 2, 2024

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:

image

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.

lionengine123 avatar lionengine123 commented on July 2, 2024

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.

lionengine123 avatar lionengine123 commented on July 2, 2024

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.

snakefoot avatar snakefoot commented on July 2, 2024

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.

snakefoot avatar snakefoot commented on July 2, 2024

Closing issue as answered due to inactivity

from nlog.windows.forms.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.