Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

NLog - Targetübergabe

Empfohlene Antworten

Veröffentlicht

Hallo ,

ich wollte ma fragen ob jmd. schonma mit NLog gearbeitet hat , wenn ja ist meine Frage wie kann ich den Speicherort der LogFile festsetzen ?

Ich habe mich an folgendem probiert :

Target klasse


[Target("MyFirst")]

...

  class myTarget:TargetWithLayout

  {

    private string _host = "localhost";


    public string Host

    {

      get { return _host; }

      set { _host = value; }

    }


    protected override void Write(LogEventInfo logEvent)

    {

      string logMessage = CompiledLayout.GetFormattedMessage(logEvent);


      SendTheMessageToRemoteHost(this.Host, logMessage);

    }

...


und der Aufruf sieht wie folgt aus :

      myTarget tar = new myTarget();

      logger.Factory.Configuration.AddTarget("myFirst", tar);

oder folgendes :

logger.Factory.Configuration=     LogManager.Configuration = new XmlLoggingConfiguration("C:\\.....\\Desktop\\NLOG.txt") ;

MfG Oxy

Ok habs nu herausgefunden :



 public partial class Window1 : Window

  {

    private static  Logger logger = LogManager.GetCurrentClassLogger();

    //myTarget tar = new myTarget();

    public Window1()

    {

      InitializeComponent();

      //Target erstellen

      NLog.Targets.FileTarget myft = new NLog.Targets.FileTarget();

      myft.FileName = "test.txt";

      myft.Name = "F1";

      //Config erstellen

      LoggingConfiguration config = new LoggingConfiguration();

      //Rule erstellen (*)= Für alle Klassen , Loglevel = Art des Fehlers , myft = Target

      LoggingRule rule = new LoggingRule("*",  LogLevel.Error, myft);

      config.LoggingRules.Add(rule);

      LogManager.Configuration = config;

      //dem Logger die Config übergeben

      logger.Factory.Configuration = config;

    }


    private void button1_Click(object sender, RoutedEventArgs e)

    {

      try

      {

        int x = int.Parse(textBox1.Text);

      }

      catch (Exception ex)

      {

        logger.Error(" "+ex);

        logger.Debug(" "+ex);

      }

    }

  }

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.