Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Apr 08 14:32

    ckadluba on dev

    * Updated NuGets: Serilog 2.9.0… Rolled back NuGet package refer… Merge pull request #258 from ck… (compare)

  • Apr 08 12:07

    ckadluba on dev

    * Updated NuGets: Serilog 2.9.0… Merge pull request #257 from ck… (compare)

  • Apr 08 08:37

    ckadluba on dev

    Added all unit tests for System… Merge pull request #256 from ck… (compare)

  • Apr 07 17:15

    ckadluba on dev

    Added all unit tests for hybrid… Added all unit tests for hybrid… Merge pull request #255 from ck… (compare)

  • Apr 07 11:13

    ckadluba on dev

    Added a test for Configuration.… Added a factory to create MSSql… * Use factories in all configur… and 2 more (compare)

  • Apr 06 14:03

    ckadluba on dev

    Added default csharp and dotnet… Merge pull request #253 from ck… (compare)

  • Apr 06 09:28

    ckadluba on dev

    Fixed all remaining code analys… Changed a public field LoggerCo… Bumped version from 5.2 to 5.3 … and 1 more (compare)

  • Apr 05 21:59

    ckadluba on dev

    Fixed deprecated NuGet properti… Added code analysis nuget in Se… Merge pull request #251 from ck… (compare)

  • Apr 05 18:57

    ckadluba on dev

    Added a test for ClusteredColum… Merge pull request #250 from ck… (compare)

  • Apr 05 17:20

    ckadluba on dev

    AppVeyor build changes: * Use V… Merge pull request #249 from ck… (compare)

  • Apr 05 00:58

    ckadluba on dev

    Renamed TestJsonLogEventFormatt… Added CombinedConfigDemo sample… Added unit tests for MicrosoftE… and 1 more (compare)

  • Apr 03 23:13

    ckadluba on dev

    * Fixed unit test parallel exec… Fixed long duration of test Ext… Merge pull request #247 from ck… (compare)

  • Apr 03 22:52

    RLittlesII on xamarin-mac

    Add basic Xamarin.Mac support (… (compare)

  • Apr 03 22:50

    RLittlesII on xamarin-mac

    (compare)

  • Apr 03 22:44

    RLittlesII on xamarin-mac

    Migrate to Sdk-style Removed more cruft from the .cs… Just use .NET Standard instead and 3 more (compare)

  • Apr 03 22:37

    RLittlesII on master

    Update LoggerConfigurationXamar… (compare)

  • Apr 03 17:16

    ckadluba on dev

    In DatabaseFixture for tests: d… Removed some unecessary "use da… Merge pull request #245 from ck… (compare)

  • Apr 03 14:05

    niemyjski on v67

    (compare)

  • Apr 03 14:05

    niemyjski on master

    Updated references (compare)

  • Apr 03 12:10

    ckadluba on dev

    Moved configuration extensions … Refactored for testablility: sp… Added tests for SqlTableCreator. and 5 more (compare)

awygle
@awygle
hi all, can i use the sqlite sink with a ":memory:" sqlite database? if so, how? currently an exception is being thrown
awygle
@awygle
By looking at the code the answer appears to be "no", which is unfortunate :/
Ruben Bartelink
@bartelink
@velcrocodile_twitter sorry; misunderstood. Yes, you can do (Log.IsEnabled(Debug) ? Log.ForContext("details",details) : Log.Logger).Information("Might have context")
@awygle it can be well worth asking on SO with some details about use case (and posting a link back here in case someone happens to know). That and trying https://getseq.net ;)
Jinendra Ghodke
@JinendraGhodke
Hi, for structured logging we can write the objects. But is there any way that we can define annotations on fields of the class. And when writing object only annotated fields will be considered?
Nicholas Blumhardt
@nblumhardt
@JinendraGhodke Hi! https://github.com/destructurama/attributed might be what you're looking for (or be able to be modified for it). HTH!
Jinendra Ghodke
@JinendraGhodke
@nblumhardt This is exactly what I was looking for. thanks a lot.
Alex Rogers
@Skyhighjinks_gitlab
Serilog.Log.Logger = new Serilog.LoggerConfiguration()
                            .ReadFrom.AppSettings()
                            .CreateLogger();
Does anyone know why the .AppSettings wont compile?
Trying to use Web.Config AppSettings
Ruben Bartelink
@bartelink
@Skyhighjinks_gitlab maybe ask on SO (mention what packages/versions are you using, are you following some tutorial) and post a link back here?
Sebastian Loncar
@arakis
How to have only the Class name of SourceContext in the Console Sink? {SourceContext} gives me the fully qualified Name.
If course, i could use ForContext(nameof(MyClass)), but ForContext<Type>() is nicer :-)
Ruben Bartelink
@bartelink
you use an enricher to put an modified form of it into the properties before ths sink gets it, and refer to that prop in the template @arakis
Sebastian Loncar
@arakis
thx, got it working!
Russ Hammett
@Kritner

Hey guys, I'm using appsettings.json style configuration for serilog, and was wondering what the json looks like (assuming it exists?) for doing assembly based changes of the minimum log level. I found a property called "overrides" but i didn't see in the documentation if this is actually how to do it, but what i tried did not work.

was hoping for something like this:

"Serilog": {
      "MinimumLevel": "Debug",
      "Overrides": [
        {"System": "Warning"},
        {"Microsoft": "Warning"}
      ]
}
Apoorv Upadhyay
@apoorvup_twitter
Hi all. I need help in Implemeting Serilog in my WPF project.
public class LoggerFactory : ILoggerFactory
    {
        Func<string> headerFactory = () => "date time;logtype;environment;ShipTracker build version;test case description;status";
        public Serilog.Core.Logger Create()
        {
            var logger = new LoggerConfiguration()
                .WriteTo.File(new CustomCsvLogging(), $"C:\\Dev\\Logs\\shiptracker-ui-{DateTime.Now}log.csv", hooks: new HeaderWriter(headerFactory))
               // .ReadFrom.AppSettings()
                .CreateLogger();
            return logger;
        }
    }
my CustomCsvLogging() is
  public class CustomCsvLogging: ITextFormatter
    {
        public void Format(LogEvent logEvent, TextWriter output)
        {
            output.Write(logEvent.Timestamp.ToString("dd-MM-yyyy H:mm"));
            output.Write(";");
            output.Write(logEvent.Level);
            output.Write(";");
            output.Write(logEvent.Properties[Configuration.Config.SynergyEnvironment]);
            output.Write(";");
            output.Write(logEvent.Properties["KEY"]); //App Build version
            output.Write(";");
            output.Write(logEvent.Properties["KEY"]); //test case description
            output.Write(";");
            output.Write(logEvent.Properties["KEY"]); //test status

            output.WriteLine();
        }

    }
I want to know output.Write(logEvent.Properties["KEY"]); for the header mentioned above and how to write values
Apoorv Upadhyay
@apoorvup_twitter
This is the sample output I need
date time       | logtype    |environment| app build version| test case description | status
02-04-2020 4:30 | Test Reults|aBC06      |2.0.150           | Loading Views         | Success
Apoorv Upadhyay
@apoorvup_twitter
I am very new to this. I want to write values
Russ Hammett
@Kritner

Hey guys, I'm using appsettings.json style configuration for serilog, and was wondering what the json looks like (assuming it exists?) for doing assembly based changes of the minimum log level. I found a property called "overrides" but i didn't see in the documentation if this is actually how to do it, but what i tried did not work.

was hoping for something like this:

"Serilog": {
      "MinimumLevel": "Debug",
      "Overrides": [
        {"System": "Warning"},
        {"Microsoft": "Warning"}
      ]
}

FYI found it:

{
    "Serilog": {
        "MinimumLevel": {
            "Default": "Debug",
            "Override": {
                "System": "Warning",
                "Microsoft": "Warning"
            }
        }
    }
}
Nicholas Blumhardt
@nblumhardt
@Kritner thanks for the follow-up :+1:
@apoorvup_twitter this might be a good one for Stack Overflow, there's a bit much detail to cover in chat format; I'll keep an eye on the serilog tag and try to help out if I spot it
jstafford5380
@jstafford5380
Anyone know how see the log level at run time? I don't want to change it, I literally just want to see if it's picking up settings correctly.
Alexandre_P
@a540_p_twitter
Good Morning
I have a question for you. I would like create a filter by class like we can have with "Override": {
"Microsoft": "Information",
Ruben Bartelink
@bartelink
@a540_p_twitter you'll have more success if you send a fully-formed question on StackOverflow tagged serilog
Apoorv Upadhyay
@apoorvup_twitter
@bartelink can you help me with my question. No help is arriving and my implementation is struck. I have posted the SO link above
Ruben Bartelink
@bartelink
@apoorvup_twitter firstly, I'd figure out what you want to do - use serilog, or raw code
If you're not very familiar with Serilog, I'd just write raw code like the answer suggests
If not, you're essentially writing a custom sink
At which point I'd have to ask: why?
I'd be looking to use getseq.net and/or use some low tech thing like opening the files in VS Code
Half the problem on your SO thread is that you havent truly answered any of the above
Your far more likely to get places out there, than atting folks here unfortunately
(I do appreciate you went to the trouble of writing on SO first and linking here and don't mind helping a bit - this is simply a matter of finding someone that has done what you want that has time - I have never felt motivated to write a custom sink outside of a test scenario)
Apoorv Upadhyay
@apoorvup_twitter
what is the problem that you see there?
I had a basic serilog logger in place that writes to an txt file. I wanted to extend the functionality by using custom sync and write few data as mentioned in the SO problem
Ruben Bartelink
@bartelink
what is the questions that you see in my post above
what are your answers
we won't get far with this line of conversation
Neither me, nor anyone else can get you where you're looking to go if you're not going to share more context
ok, now we're talking...
I'd say you need to go look at custom sinks and simply write the thing - it'll be well worth the learning experience
Apoorv Upadhyay
@apoorvup_twitter
So, as I already have the logger dlls and even the sync think in place. I thought it would be easy to implement the writing to csv.
CustomSync are not helping as I am a begineer
Ruben Bartelink
@bartelink
if you're want people to solve a problem, you'll need to follow the SO question asking guide - TL;DR:
  1. my code is this
  2. it writes this out
  3. I expect this instead:
    if you're not surfacing such context, nobody can guess what you need
I unfortunately don't have time now to drill in, sorry
Apoorv Upadhyay
@apoorvup_twitter
The question is not clear.
Help me once you feel free.
Ruben Bartelink
@bartelink
Unfortunately, any help I'd render would simply consist of me breaking down the advice above
  1. go to SO
  2. show your work so far
  3. explain the problem
  4. profit...
Apoorv Upadhyay
@apoorvup_twitter
thanks
Ruben Bartelink
@bartelink
good luck @apoorvup_twitter - if you can show your workings so far, I think it would be reasonable to post a new SO question linking back to the original - posting it here would be reasonable too
but I dont want to set too high expectations for a what is a watercooler channel for folks generally ineterested in serilog - ultimately your question is ideally progressed on stack overflow
Bayonle
@Bayonle
I hope someone can help with this. I'm logging to elastic search in my dotnet core application but keep getting this exception
Unhandled Exception:
Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object.
   at System.Net.Http.WinHttpRequestCallback.RequestCallback(IntPtr handle, WinHttpRequestState state, UInt32 internetStatus, IntPtr statusInformation, UInt32 statusInformationLength)
   at System.Net.Http.WinHttpRequestCallback.WinHttpCallback(IntPtr handle, IntPtr context, UInt32 internetStatus, IntPtr statusInformation, UInt32 statusInformationLength)
   at Interop.WinHttp.WinHttpCloseHandle(IntPtr handle)
   at Interop.WinHttp.SafeWinHttpHandle.ReleaseHandle()
   at System.Runtime.InteropServices.SafeHandle.InternalDispose()
   at System.Net.Http.WinHttpRequestState.ClearSendRequestState()
   at System.Net.Http.WinHttpHandler.<StartRequest>d__105.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadPoolWorkQueue.Dispatch()
Elasticsearch.Net.ElasticsearchClientException: An error occurred while sending
the request.. Call: Status code unknown from: GET /_cat/nodes?h=v ---> System.Net.Http.HttpRequestException: An error occurred while sending the request. ---> System.Net.Http.WinHttpException: The parameter is incorrect
   at System.Net.Http.WinHttpException.ThrowExceptionUsingLastError()
   at System.Net.Http.WinHttpHandler.InternalSendRequestAsync(WinHttpRequestState state)
   at System.Net.Http.WinHttpHandler.<StartRequest>d__105.MoveNext()
   --- End of inner exception stack trace ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
   at System.Net.Http.HttpClient.<FinishSendAsyncUnbuffered>d__59.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Elasticsearch.Net.HttpConnection.Request[TResponse](RequestData requestData)
   --- End of inner exception stack trace ---
   at Elasticsearch.Net.Transport`1.HandleElasticsearchClientException(RequestData data, Exception clientException, IElasticsearchResponse response)
   at Elasticsearch.Net.Transport`1.FinalizeResponse[TResponse](RequestData requestData, IRequestPipeline pipeline, List`1 seenExceptions, TResponse response)
   at Elasticsearch.Net.Transport`1.Request[TResponse](HttpMethod method, Stringpath, PostData data, IRequestParameters requestParameters)
   at Elasticsearch.Net.Specification.CatApi.LowLevelCatNamespace.Nodes[TResponse](CatNodesRequestParameters requestParameters)
   at Serilog.Sinks.Elasticsearch.ElasticsearchSinkState.DiscoverClusterVersion()
   at Serilog.Sinks.Elasticsearch.ElasticsearchSink..ctor(ElasticsearchSinkOptions options)
   at Serilog.LoggerConfigurationElasticsearchExtensions.Elasticsearch(LoggerSinkConfiguration loggerSinkConfiguration, ElasticsearchSinkOptions options)
   at MoneyPal.LoanScoringAndApprovalTask.ConsoleDIFactory.SetLogger()

I have my configuration like this

            var environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");
            var uri = Configuration["ElasticConfiguration:Uri"];
            var indexFormat = $"{Assembly.GetExecutingAssembly().GetName().Name.ToLower().Replace(".", "-")}-{environment?.ToLower().Replace(".", "-")}-{DateTime.UtcNow:yyyy-MM}";
            var deadLetterIndexFormat = $"{Assembly.GetExecutingAssembly().GetName().Name.ToLower().Replace(".", "-")}-{environment?.ToLower().Replace(".", "-")}-deadletter-{DateTime.UtcNow:yyyy-MM}";

            Log.Logger = new LoggerConfiguration()
             .MinimumLevel.Verbose()
            .MinimumLevel.Override("Microsoft", LogEventLevel.Warning
            .Enrich.FromLogContext()
            .Enrich.WithExceptionDetails()
            .Enrich.WithMachineName()
            .WriteTo.Debug()
            .WriteTo.Console()
            .WriteTo.Elasticsearch(
                new ElasticsearchSinkOptions(new Uri(uri))
                {
                    AutoRegisterTemplate = true,
                    IndexFormat = indexFormat,
                    // DeadLetterIndexName = deadLetterIndexFormat,
                    // DetectElasticsearchVersion = true,
                    // RegisterTemplateFailure = RegisterTemplateRecovery.IndexAnyway

                })
            .Enrich.WithProperty("Environment", environment)
            .CreateLogger();

I can ping the elasticsearch server and also telnet on port 9200 without issues. A get call to the endpoint /_cat/nodes?h=v spits out the version of elasticsearch. The elasticsearch server is up and running. I've tried to restart it but it still didn't fix the issue. I"m running a dotnetcore 2.0 applicaition.

Nicholas Blumhardt
@nblumhardt
Hi all :wave: ... found some time to look at the staged logger initialization problem and put together: https://github.com/nblumhardt/serilog-reload - all feedback and sanity checking welcome (the code's still a proof-of-concept)