'c# NLog how to get only one logfile with the longdate as filename

Hello I am using for my console application NLog for logging. With that being said I would like to log everything that happens in the console using NLog to set that up I am using the NLOG.config:

  <target name="FullCSVFile" xsi:type="File"  fileName="logs\internal_${date:format=yyyyMMdd_HHmmss}.log" keepFileOpen="true">
  <layout xsi:type="CsvLayout">
    <column name="Console" layout="${message}" />
    <column name="Error" layout="${exception:format=ToString}" />
  </layout>
</target>

<logger minlevel="Debug" name="*" writeTo="FullCSVFile" />

But this way the tool makes a new file every second passed in the console, but I want to make one file when the tool starts with that timestamp and write everything in this one. How would I do that?



Solution 1:[1]

Something like this could work, but I have not tested it:

  <variable name="started" value="${date:format=yyyyMMdd_HHmmss}"/>
  <target name="FullCSVFile" xsi:type="File" fileName="logs\internal_${started}.log" keepFileOpen="true">
    <layout xsi:type="CsvLayout">
      <column name="Console" layout="${message}" />
      <column name="Error" layout="${exception:format=ToString}" />
    </layout>
  </target>

The idea is similar to the example from the documentation: https://github.com/nlog/nlog/wiki/Configuration-file#variables

Solution 2:[2]

The following formula would also return the correct Named Range according to the Range defined in Products:

=INDIRECT(IFNA(VLOOKUP(A2:A,Products!A2:Z,4, FALSE), ""))

However, Data Validation lists in Google Sheets don't accept formulas as input. In order to avoid having to create a "Helper column" for each row in Stock to populate the drop-down list, using Apps Scripts, you can achieve that with the Simple Trigger onEdit() to populate the Sizes column depending on the selected "Code".

Sample code (edit):



function onEdit(){
  //This method runs every time a cell is modified
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var ws = ss.getActiveSheet();
  
  var activeCell = ws.getActiveCell();

  if (activeCell.getColumn() == 10 && activeCell.getRow() > 1 && ws.getSheetName() == "Pending") { //Only runs if the value changed is on the "J" column of Pending except first row
    var wsStyles = ss.getSheetByName("Styles");
    var selectedValue = activeCell.getValue();

    activeCell.offset(0, 2).clearContent().clearDataValidations().setValue("Loading...");

    //Get style Range column from Styles based on Code
    var styles = wsStyles.getDataRange().getValues();
    var rangeStyle = "";

    for (row of styles) { //looping through Styles and storing Range value in rangeStyle
      if (row[0] == selectedValue) {
        //Slightly edit here, since the Size name defined in Styles contains spaces, which Named Ranges doesn't accept as valid
        //Make sure to declare your named ranges exactly as declared in "Styles" but replacing any spaces with "_" in order for this code to run
        rangeStyle = row[2].replace(" ", "_"); 
        break
      }
    }
    
    //Looping through defined Named Ranges to identify and set drop-down list
    var namedRangeList = ss.getNamedRanges();
    for (namedRange of namedRangeList) {
      if (namedRange.getName() == rangeStyle) { //if the Range name defined in Styles is the same as Named Range name...
        var rangeSizes = namedRange.getRange();

        activeCell.offset(0, 2).clearContent().clearDataValidations(); //cleaning column D from the modified row
        var validationRule = SpreadsheetApp.newDataValidation().requireValueInRange(rangeSizes).build(); //Instantiating DataValidation object with the range of data retrieved previously
        activeCell.offset(0, 2).setDataValidation(validationRule); //Setting DataValidation object as value of column D from the modified row

      }
    }
  }
}

  • EDIT: Make sure to declare your Named Ranges replacing spaces with "_" for this code to work on the new Sheet provided.

Solution 3:[3]

you can get this with:

=INDEX(IFNA(VLOOKUP(VLOOKUP(A2:A, Products!A1:D, 4, 0), 
 SPLIT(SUBSTITUTE(TRIM(FLATTEN(
 QUERY(Sizes!A1:C,,9^9))), " ", "×", 1), "×"), 2, 0)))

but to turn it into dropdowns try:

enter image description here

enter image description here

enter image description here

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Julian
Solution 2
Solution 3 player0