Serilog

wolfram.windisch's Avatar

wolfram.windisch

22 Aug, 2017 06:52 PM

Is there a sample how to write to seq by using serilog with postsharp diagnostic?
If not can you please give me a hint or a sample..

As I far I have seen you install serilog with version 1.5. How upgrade it to latest version I would like to use enrichment from serilog.

thank you

  1. Support Staff 1 Posted by PostSharp Techn... on 25 Aug, 2017 10:49 AM

    PostSharp Technologies's Avatar

    Hello,

    the version we are installing is a minimum version required by the logging backend. You can upgrade it to the latest version (right click on a project, select Manage NuGet package, find the installed Serilog package and upgrade it to the latest version).

    A simple sample with console sink follows:

    class Program
    {
        static void Main(string[] args)
        {
            Log.Logger = new LoggerConfiguration()
                .MinimumLevel.Debug()
                .WriteTo.LiterateConsole()
                .CreateLogger();
            LoggingServices.DefaultBackend = new SerilogLoggingBackend();
    
            Log.Information("Hello, world!");
    
            Foo(42);
        }
    
        [Log("detailed")]
        public static int Foo(int x)
        {
            return x;
        }
    }
    

    Note that you need to initialize the logging backend before invoking any method that is enhanced by our aspect.

    Please let us know if you need anything else to help with.

    Best regards,
    Daniel

  2. 2 Posted by wolfram.windisc... on 30 Aug, 2017 09:30 AM

    wolfram.windisch's Avatar

    Thank you for answering

    I implemented as you suggested, but the I can not see a log from Postsharp in seq!

    I'm sure I miss something
    Thank you

    if Created a GlobalAspects.cs

    using PostSharp.Patterns.Diagnostics;
    using PostSharp.Extensibility;

    [assembly: Log(AttributePriority = 1, AttributeTargetMemberAttributes = MulticastAttributes.Private | MulticastAttributes.Protected | MulticastAttributes.Internal | MulticastAttributes.Public)]
    [assembly: Log(AttributePriority = 2, AttributeExclude = true, AttributeTargetMembers = "get_*")]

    ------------------------

     [Log(AttributeExclude = true)]
        public class Program
        {
            static void Main(string[] args)
            {
     
                LoggingServices.DefaultBackend = new SerilogLoggingBackend();

                Log.Logger = new LoggerConfiguration()
                      .MinimumLevel.Debug().
                      WriteTo.Seq("http://localhost:5341").
                      CreateLogger();

                Log.Information("RUnning"); // this is Logged to seq

                IObjectSpace obj = FormulaLogic.Core.objspcCreator.CreateAObjectSpace();

                Farbverwaltung.Module.ERPInputRun _run = obj.FindObject<ERPInputRun>(CriteriaOperator.Parse(""));

                ImportValidieren _imp = new ImportValidieren();
                _imp.Validieren(_run);
            }
        }
    }

        public class ImportValidieren
        {

            IObjectSpace obj;

            public ImportValidieren()
            {
                obj = FormulaLogic.Core.objspcCreator.CreateAObjectSpace();

            }

            [Log("detailed")] // this is not logged
            public void Validieren(ERPInputRun transaction)
            {

                var res1 = obj.GetObjectsQuery<ERPInputRecipe>().Where(x => x.ERPInputRun.TransactionID == transaction.TransactionID);

                foreach (var item in res1)
                {
                    var _roh1 = obj.GetObjectsQuery<ERPInputRawMaterial>().Where(x => x.Rohstoffnr == item.Rohstoffnr);
                    if (_roh1.Count() > 0) continue;
                    var _roh2 = obj.GetObjectsQuery<Rohstoff>().Where(x => x.Rohstoffnr == item.Rohstoffnr);

                    Fehler _f = new Fehler();
                    _f.RegisterError(String.Format("Rohstoff {0} nicht vorhanden", item.Rezeptnr));

                }

                var res = obj.GetObjectsQuery<ERPInputOrder>().Where(x => x.ERPInputRun.TransactionID == transaction.TransactionID);

                foreach (var item in res)
                {
                    var _roh1 = obj.GetObjectsQuery<ERPInputRecipe>().Where(x => x.Rezeptnr == item.Rezeptnr);
                    if (_roh1.Count() > 0) continue;
                    var _roh2 = obj.GetObjectsQuery<Rezept>().Where(x => x.Rezeptnr == item.Rezeptnr);

                    Fehler _f = new Fehler();
                    _f.RegisterError(String.Format("Rezept {0} nicht vorhanden", item.Rezeptnr));
                   
                }

                foreach (var item in res)
                {
                    var dosbeh = obj.GetObjectsQuery<Dosierbehälter>().Where(x => x.Behälternr_Alpha == item.Dosierbehaelternr);
                    if (dosbeh.Count() > 0) continue;
                    Fehler _f = new Fehler();
                    _f.RegisterError(String.Format("Dosierbehaelter {0} nicht vorhanden", item.Dosierbehaelternr));
                }

           

            }

        }

  3. 3 Posted by wolfram.windisc... on 30 Aug, 2017 09:31 AM

    wolfram.windisch's Avatar

    ADD ON
    I registered Postsharp but still it's complaining that there is no valid Licence...

  4. Support Staff 4 Posted by PostSharp Techn... on 01 Sep, 2017 02:32 PM

    PostSharp Technologies's Avatar

    Hello,

    I apologize for the late answer.

    The problem seems to be with profile "detailed":

     [Log("detailed")] // this is not logged
    

    I guess, that the profile is not defined in postsharp.config file.

    You can remove the profile name argument from Log attribute:

     [Log]
    

    Then you use the "default" profile, which logs a message when target methods start, complete, or throws an exception.

    If you want to use the "detailed" profile, you can define it in postsharp.config file like this:

    <?xml version="1.0" encoding="utf-8"?>
    <Project xmlns="http://schemas.postsharp.org/1.0/configuration">
      <Logging xmlns="clr-namespace:PostSharp.Patterns.Diagnostics;assembly:PostSharp.Patterns.Diagnostics" >
        <Profiles>
          <LoggingProfile Name="detailed" IncludeSourceLineInfo="True" IncludeExecutionTime="True">
            <DefaultOptions>
              <LoggingOptions IncludeParameterType="True" IncludeGenericParameters="True" IncludeParameterValue="True" IncludeParameterName="True" IncludeReturnValue="True" Level="Trace" />
            </DefaultOptions>
            <ExceptionOptions>
              <LoggingOptions IncludeParameterType="True" IncludeGenericParameters="True" IncludeParameterValue="True" IncludeParameterName="True" IncludeReturnValue="True" Level="Error" />
            </ExceptionOptions>
          </LoggingProfile>
        </Profiles>
      </Logging>
    </Project>
    

    You can learn more about logging configuration in PostSharp documentation: http://doc.postsharp.net/logging-customizing

    Please, what error message PostSharp shows? Is it in a build log? Please, do you see the license key in Visual Studio on PostSharp/Options.../License dialog? If you don't have PostSharp Tools for Visual Studio installed, you can start %programdata%\PostSharp<your postsharp nuget package version>\bin.Release\postsharp.settings.UI.exe and open Manage Licenses.

    If you see your license key here, please could you generate a licensing diagnostic log by building your project with the following command line:

    msbuild /p:PostSharpTraceLicensing=True
    

    The log file is created in the %ProgramData%\PostSharp\LicensingTrace directory. The full path to the log file is mentioned in the build output.

    -jakub

  5. Support Staff 5 Posted by PostSharp Techn... on 13 Sep, 2017 09:20 AM

    PostSharp Technologies's Avatar

    Hello,

    We are going to close this request as there have not been any further updates. Please feel free to reopen the discussion if you need more help.

    Thanks,
    PostSharp Team

  6. PostSharp Technologies closed this discussion on 13 Sep, 2017 09:20 AM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac