Skip to content

How do I disable logging? #9

Open

Description

@beppe9000

I would like to disable the automatic uhttpsharp log in my console application by either some boolean flag or by changing the logger level. Any help?

Activity

  1. bonesoul commented on Jul 29, 2016

    @bonesoul
    Owner

    only console.write reference is in the demo project? are you sure the log lines you mention are from uhttpsharp?

  2. beppe9000 commented on Jul 29, 2016

    @beppe9000
    Author

    This one, for example:

    Logger.InfoFormat("Embedded uhttpserver started.");

  3. sirkris commented on Feb 6, 2019

    @sirkris

    Bump! I would really love to know how to disable this annoying message every time I use the library:

    Exception occured resolving a log provider. Logging for this assembly uhttpsharp
    , Version=0.1.5653.28566, Culture=neutral, PublicKeyToken=null is disabled. Syst
    em.TypeInitializationException: The type initializer for 'uhttpsharp.Logging.Log
    Providers.ColouredConsoleLogProvider' threw an exception. ---> System.InvalidOpe
    rationException: System.Console or System.ConsoleColor type not found
    at uhttpsharp.Logging.LogProviders.ColouredConsoleLogProvider..cctor() in c:
    Users\shani\Documents\GitHub\uHttpSharp\uhttpsharp\App_Packages\LibLog.3.1\LibLo
    g.cs:line 1629
    --- End of inner exception stack trace ---
    at uhttpsharp.Logging.LogProviders.ColouredConsoleLogProvider.IsLoggerAvailab
    le() in c:\Users\shani\Documents\GitHub\uHttpSharp\uhttpsharp\App_Packages\LibLo
    g.3.1\LibLog.cs:line 1645
    at uhttpsharp.Logging.LogProvider.ResolveLogProvider() in c:\Users\shani\Docu
    ments\GitHub\uHttpSharp\uhttpsharp\App_Packages\LibLog.3.1\LibLog.cs:line 453

    Why can't you just let the exception bubble up so I can catch it?

  4. isen-ng commented on Feb 20, 2019

    @isen-ng

    Do this for a work around:

            static YourClass()
            {
                LogProvider.LogProviderResolvers.Add(
                    new Tuple<LogProvider.IsLoggerAvailable, LogProvider.CreateLogProvider>(() => true,
                        () => NullLoggerProvider.Instance));
            }
    
            public class NullLoggerProvider : ILogProvider
            {
                public static readonly NullLoggerProvider Instance = new NullLoggerProvider();
                
                private static readonly ILog NullLogInstance = new NullLog();
                
                public ILog GetLogger(string name)
                {
                    return NullLogInstance;
                }
    
                public IDisposable OpenNestedContext(string message)
                {
                    return null;
                }
    
                public IDisposable OpenMappedContext(string key, string value)
                {
                    return null;
                }
                
                public class NullLog : ILog
                {
                    public bool Log(LogLevel logLevel, Func<string> messageFunc, Exception exception = null, params object[] formatParameters)
                    {
                        // do nothing
                        return true;
                    }
                }
            }
    
  5. robie2011 commented on May 26, 2020

    @robie2011

    same issue. Workaround didn't work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions