Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Rolf Kristensen
    @snakefoot
    @StevenLiekens There is something new called configuration-by-code, and I like it. Prefer to have documented history of machine-configuration-changes. Who did what? and why?. If saving to a different repository works, then I would go for that.
    Steven Liekens
    @StevenLiekens
    We're currently trying to move our configs (including nlog.config) into a VSTS release pipeline
    asnaseer-resilient
    @asnaseer-resilient
    @snakefoot Thanks for your help
    Flash Deviant
    @FlashDeviant

    Hi everyone, not sure if you can help with this but Im trying to setup NLog.LiteDB but I'm getting a System.MissingMethodException in the internal log:

    2018-08-31 12:14:02.3828 Error Error when writing to LiteDB System.MissingMethodException: Method not found: 'Void LiteDB.LiteDatabase..ctor(System.String, LiteDB.BsonMapper)'.
       at NLog.LiteDB.LiteDBTarget.<GetCollection>b__42_0(String k)
       at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
       at NLog.LiteDB.LiteDBTarget.GetCollection()
       at NLog.LiteDB.LiteDBTarget.Write(LogEventInfo logEvent)

    I've ran the NLog.LiteDB projects unit test myself to see if the project is at fault and it works fine so I guess the problem lies in my solution

    Rolf Kristensen
    @snakefoot
    There is a breaking change in LiteDB here: https://github.com/mbdavid/LiteDB/commit/5acd303abce92cf24b9cfac2bdd8b709fcaa26b2#diff-df389abff6d3dc434933ac4d4bb7e07b (Parameter added to constructor). So unless using LiteDb ver. 3.1.0, then you need to recompile the LiteDBTarget yourself to handle this breaking change.
    Dane Watson
    @deedubb83_twitter
    Hello Nloggers -- I am making a multitenant application that has 1 generic 'service' log, then seperate logs for each customer. The customer number comes from the DB so I'm trying to make a new logger in code. I instantiate a logger, I copy attributes from the generic logger changing the filename & archive filename... The ${logger} value is getting updated but they are all going into the same file. Can you make me less newbie?
    Dane Watson
    @deedubb83_twitter
    I have solved it myself but I'm not exactly sure when I fixed it... <rules><logger name="DicomRepositoryService*" minlevel="Debug" writeTo="AsyncFile" /></rules> -- that asterisks is important ;-)
    Ronny Hanssen
    @Spiralis
    I am planning on using a logger with a filter and a when, where the condition uses an ${environment:MYVAR}. While my application is running, will NLog be able to change the logger based on changing the given environment variable - or will a restart be required in order for NLog to pick up the change?
    Rolf Kristensen
    @snakefoot
    Ronny Hanssen
    @Spiralis
    @snakefoot I\Maybe I got it wrong, but it felt like none of the links you gave me indicates an option to change the value run-time, using an environment variable. As of now, we have to change the config-file, which does work. That is, it is picking up the change without restarting the application. But, this also means that one easily can forget to change the config-file back when analysis is done. Typically you increase the log-level in the config during analysing an issue, then you forget to change it back, and the logs keep piling up. Now, if the change was temporary, somehow, then a restart of the application would reset back to the original settings.
    So, I am looking for a way to set i.e. a Trace level, for a given namespace and then if you forget, it will return back to normal after a given time - or at least on next restart.
    Like, if NLog had it's own rest-interface that it responded to for controlling things like this, we could set a temporary log-level for a given name-space. Maybe even requiring a timer or defaulting it to i.e. 60 min.
    I see that I can do this by adding our own API to the application and using the NLog internal API of course. But, it would be nice if this already had a solution in Nlog. AFAICT this feature does not exist as of today, no?
    Rolf Kristensen
    @snakefoot
    @Spiralis The first stackoverflow-link shows an example for how to doing dynamic-filter with environment-variable that contains minlevel. There is currently no logic for dynamic loading of the entire logging rules section from a different external config-source. But you can always setup a Timer to restore the logging-rules, after having replaced them at runtime.
    Julian Verdurmen
    @304NotModified

    Is there someone with a good idea how to improve the documentation of NLog, and would like to help us with that? :)

    (If it's good enough, that also good to know :)

    lobster2012-user
    @lobster2012-user
    Including*
    Hi! What do you think about the use of variables on the way for the internal log. At least a variable environment.? 2. Load the configuration from the line, not just file. 3. Including on the link, and not only the file.
    Rolf Kristensen
    @snakefoot
    @lobster2012-user Not sure I understand your question. Are you talking about supporting NLog Variables for the configuration of InternalLogger FilePath? Or NLog Variables for InternalLogger LogLevel ? The InternalLogger configuration is setup before having loaded NLog Variables.
    lobster2012-user
    @lobster2012-user
    'InternalLogger FilePath'
    That is the problem. For many applications, I want to use a single template that depends on the environment variables, while I see one way out - change it on the fly on my own.
    ExpandEnviromentVariables can at least be called.
    lobster2012-user
    @lobster2012-user
    NLOG_INTERNAL_LOG_FILE
    hm
    case "INTERNALLOGFILE":
    internalLogFile = configItem.Value?.Trim();
    Here you can expand env vars, you can use a few simple targetrenderers, such as dates, variables.
    Rolf Kristensen
    @snakefoot
    @lobster2012-user NLog 4.6 includes support for environment-variables. See also https://nlog-project.org/2019/03/20/nlog-4-6-is-live.html#internallogfile-variables
    lobster2012-user
    @lobster2012-user
    @snakefoot I still need to set the name of the application to the log name. All this can be done, but it is necessary to programmatically set the variable, I will do so.
    Rolf Kristensen
    @snakefoot
    @lobster2012-user Yes changing InternalLogFile at runtime gives most freedom. Or changing the application-installer-script to update the NLog.config-file with the wanted details.
    Sean Finnegan
    @cowtrix
    hello all. I had a quick NLog question, was hoping someone would be able to help me out
    I'm using NLog with XUnit to run a test suite, but in the output I'm getting some prefixed timestamps and info:
    [14/02/2020 10:54:16 Informational] [xUnit.net 00:24:24.3870078] Starting: AutomatedTests (parallel test collections = off, max threads = 12)
    E.g. above, I am just calling NLog.Log.Info("Starting: AutomatedTests (parallel test collections = off, max threads = 12")
    Where's the timestamp and [xUnit] thing coming from?? I can't figure that out
    or how to modify that
    Rolf Kristensen
    @snakefoot
    @cowtrix I'm guessing that you are using Trace-Target. The extra output comes from the default-trace-listener. You can configure rawWrite="true" to fix this. See also https://github.com/nlog/nlog/wiki/Trace-target
    Mathieu Paquette
    @mathpaquette
    damn it, Im struggling for a while trying to use NLog and Microsoft.Extensions.Logging inside a class library project.
    I'm building a console application along with some class libraries. I dont intend to use DI and in my class library I just want to pull Microsoft.Extensions.Logging and not any concrete implementation. Do we have any working example?
    Rolf Kristensen
    @snakefoot
    @mathpaquette Little confusing that you are asking in a NLog-forum about how to use MEL without NLog. And to make things even more strange then want to use MEL without dependency injection. I'm sorry to be the messenger, but MEL and dependency-injection are very closely coupled. But lets say your class-library have a master class from which all is started, then you ensure that this master class is given MEL-ILogger / -ILoggerFactory as parameter (in constructor or in initialize method). Then all dependent classes can acquire the logger / loggerfactory from the master-class. But I think you should google "Microsoft Extension Logging Class Library" and check out stackoverflow. Pretty sure you are not the first.
    Rolf Kristensen
    @snakefoot
    @mathpaquette Found this link: NLog/NLog.Extensions.Logging#379
    Mathieu Paquette
    @mathpaquette
    @snakefoot yes but this kind odd to have to create a "middleman" static class just for the stake of it because of their crappy design.
    Rolf Kristensen
    @snakefoot
    @mathpaquette The link above is just me trying to show you are not alone (You can google for others doing "Microsoft Extension Logging Class Library"). The solution presented in the link is terrible and an ugly hack (Does not follow the guidance that I give in my initial reply). But it is the perfect solution for the one asking, since it matches his existing solution (Now with MEL-support). Like I said in my previous reply, then I would suggest you have a master-class (not a static one) where you give the MEL-Ilogger / -ILoggerFactory as parameter (in constructor or in initialize method). The master-class is then used as gateway for all class-library-functionality (I guess for a big class-library then one can have several master-classes, one for each sub-feature). Again you are asking a very wide question where no one but yourself have the ability to recognize what answer matches the design of your unique class-library.
    Mathieu Paquette
    @mathpaquette
    @snakefoot yes I totally agree with you. Dont get me wrong. I guess Im just frustrated by their implementation and the way they are imaging people consuming it only in ASP .net core. On the other hand, thanks a lot for your time. A lot appreciated !
    Sampath Reddy
    @sampath13

    Hi! I am trying to log an object using NLog with CsvLayout. Below is the config I am trying to use and did not yield results. Could someone suggest me the right config:
    <target name="logfile_error" xsi:type="File" fileName="./logs/errorLogs_nlog_csv_${date:yyyyMMdd}.csv">
    <layout xsi:type="CsvLayout" delimiter="Comma" withHeader="false">
    <column name="time" layout="${longdate}" />
    <column name="RequestMethod" layout="${event-properties:item=ErrorLog:objectPath=RequestMethod}"/>
    </layout>
    </target>

    C#:
    this._logger.Error(new ErrorLog("GET"));

    Rolf Kristensen
    @snakefoot
    @sampath13 Please check https://github.com/NLog/NLog/wiki/Logging-troubleshooting , and if that fails then create bug-issue: https://github.com/NLog/NLog/issues/new/choose (And remember to fill out the issue-template with your full nlog.config)
    NimaFx
    @NimaFx
    Hey Y'all
    I'm wondering if custom LayoutRenderer really works. I manually register one
    LogManager.Setup()
    .SetupExtensions(s =>
    s.RegisterLayoutRenderer("trace_id", (logevent) => "A")
    );
    I got this
    2020-06-16 09:20:36.7152 Error Error parsing layout trace_id will be ignored. Exception: System.ArgumentException: LayoutRenderer cannot be found: 'trace_id'
    at NLog.Config.Factory2.CreateInstance(String itemName) at NLog.Layouts.LayoutParser.GetLayoutRenderer(ConfigurationItemFactory configurationItemFactory, String name, Nullable1 throwConfigExceptions)
    I suppose RegisterLayoutRenderer is an empty method :))
    Rolf Kristensen
    @snakefoot
    @NimaFx Have replied to your issue here: NLog/NLog#4014
    philipphagen87
    @philipphagen87
    Hey, i've a question. I wrote a simple class in a class library. I want to log what happen in this class. But i want to give out the log stuff configurated from the main app. how can i solve this "problem" :-) maybe some one have a good self explaining example? thanks
    Rolf Kristensen
    @snakefoot
    @philipphagen87 Sounds like a question for stackoverflow. But I normally just do NLog.LogManager.GetCurrentClassLogger().Info("Hello World"). And then have my class-library depend on NLog. The application can then setup NLog-config for the desired output.
    philipphagen87
    @philipphagen87
    Thanks @snakefoot