Quantcast
Channel: patterns & practices – Enterprise Library
Viewing all 1928 articles
Browse latest View live

New Post: Reload or refresh the configuration

$
0
0
I want to use the Logging block to log to a particular file for some time in the program, and then change the filename after sometime. I'm using the fluent interface, but when I configure it the second time, it is not working. Is there a way to refresh or reload the config after having done it once already?
static void Main(string[] args)
{

    FirstConfig();
    Logger.LogInfoMessage("Before processing"); //Some wrapper around EntLib logger methods

    //Do some processing for some time

    SecondConfig();
    Logger.LogInfoMessage("After processing");
}

private static void FirstConfig()
{
    var textFormatter = new FormatterBuilder()
        .TextFormatterNamed("First Text Formatter")
        .UsingTemplate("{message}");

    var builder = new ConfigurationSourceBuilder();
    builder.ConfigureLogging()
        .WithOptions.DoNotRevertImpersonation()
        .LogToCategoryNamed("General").WithOptions.SetAsDefaultCategory()
        .SendTo.FlatFile("First Listener")
        .FormatWith(textFormatter).WithHeader("").WithFooter("")
        .ToFile("Logs\\BeforeChange.log");

    var configSource = new DictionaryConfigurationSource();
    builder.UpdateConfigurationWithReplace(configSource);
    EnterpriseLibraryContainer.Current = EnterpriseLibraryContainer.CreateDefaultContainer(configSource);
}

private static void SecondConfig()
{
    var textFormatter = new FormatterBuilder()
        .TextFormatterNamed("Second Text Formatter")
        .UsingTemplate("{message}");

    var builder = new ConfigurationSourceBuilder();
    builder.ConfigureLogging()
        .WithOptions.DoNotRevertImpersonation()
        .LogToCategoryNamed("General").WithOptions.SetAsDefaultCategory()
        .SendTo.FlatFile("Second Listener")
        .FormatWith(textFormatter).WithHeader("").WithFooter("")
        .ToFile("Logs\\AfterChange.log");

    var configSource = new DictionaryConfigurationSource();
    builder.UpdateConfigurationWithReplace(configSource);
    EnterpriseLibraryContainer.Current = EnterpriseLibraryContainer.CreateDefaultContainer(configSource);
}

New Post: Reload or refresh the configuration

$
0
0
You should dispose all trace listeners before performing a reconfiguration (this will release all file locks).

You can use the static Logger.Reset() to perform the dispose.
staticvoid Main(string[] args)
{

    FirstConfig();
    Logger.LogInfoMessage("Before processing"); //Some wrapper around EntLib logger methods//Do some processing for some time

    Logger.Reset();

    SecondConfig();
    Logger.LogInfoMessage("After processing");
}
Also, while disposing, you should ensure that there are no write operations performed or they will fail.

If that doesn't resolve the issue, can you elaborate on what is not working?

~~
Randy Levy
entlib.support@live.com
Enterprise Library support engineer
Support How-to

New Post: Reload or refresh the configuration

$
0
0
Oh yes, that solved it. It was not intuitive for me to find the Reset method on Logger, I was searching for similar methods in the ELContainer.
Also, while disposing, you should ensure that there are no write operations performed or they will fail.
This would not happen unless it is in a multi-threaded environment, correct?

New Post: Can I change the connection string if I use EnterpriseLibraryContainer.Current.GetInstance(..)

$
0
0
Thanks.
That works.

Just to be clear - I want to use encrypted connection strings and not encrypt the entire config file.

Is this the right way of doing it - that is, the EL does not support this already - I don't think it does as it seems to link to the <connectionstrings> element seamlessly.

New Post: How can the SqlDatabaseSink store the payload in separate columns?

$
0
0
How can the SqlDatabaseSink store the payload in separate columns? It's mentioned in the documentation, but I haven't seen it done anywhere. When I've tried, the payload is always stored as a JSON string. Any ideas?

Source: Developing event sources using the .NET EventSource class

Under "Specifying the event and its payload" it stated:
Some sinks will store payload items individually; for example, the SQL Database sink and the Azure Table Storage sink in the Semantic Logging Application Block store each payload item in a separate column.
Is the documentation wrong regarding the SqlDatabaseSink? I've heard DEVs claim that the Azure Sink works.

New Post: Hanging when I execute EnterpriseLibraryContainer.Current.GetInstance(ConnectionStringName);

$
0
0
Hi,

Is there any reason why this code would cause hanging?

The bad news is that is does not happen every time.

I would like to know what happens under the hood when this line is executed and that may help me find an answer.

Thanks
Jason

New Post: How can the SqlDatabaseSink store the payload in separate columns?

$
0
0
Yes, that does seem like a bug in the documentation. Thanks for pointing it out. The Azure Sink has a dynamic schema so the payload values are available in separate columns.

~~
Randy Levy
entlib.support@live.com
Enterprise Library support engineer
Support How-to

New Post: Hanging when I execute EnterpriseLibraryContainer.Current.GetInstance(ConnectionStringName);

$
0
0
You can download the Enterprise Library 5 source code from the Download Center: http://www.microsoft.com/en-us/download/details.aspx?id=15104

Not sure if this is the issue but trying to retrieve objects from the container while (concurrently) performing a re-configuration of the container could definitely cause issues. In that case, you should ensure that GetInstance waits until the re-configuration is complete. Usually bootstrapping of the container is performed once at startup before the application processes requests.

~~
Randy Levy
entlib.support@live.com
Enterprise Library support engineer
Support How-to

New Post: Semantic Logging - Out of process

$
0
0
I have created dll called “SemanticLogging.CustomSink”. It will have code for custom sink implementation to write log file to azure blob storage.


Please find and review attached xml file.


When I try this in “In process” it is working fine.


I have taken this dll and moved to semantic logging out of process implemented folder. But while I’m executing this, it is throwing me below error.



Error:


C:\Users\saravana_ayyadurai\Desktop\SemanticLoggingService>SemanticLogging-svc.exe -console
Enterprise Library Semantic Logging Service v1.0.1304.0
Microsoft Enterprise Library
Microsoft Corporation



One or more errors occurred when loading the TraceEventService configuration file.
Could not load type 'SemanticLogging.CustomSink' from assembly 'Microsoft.Practices.EnterpriseLibrary.SemanticLogging.Etw, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35'.

Configuration element:
<customSink name="customblobsink" type="SemanticLogging.CustomSink" xmlns="http://schemas.microsoft.com/practices/2013/entlib/semanticlogging/etw">



Kindly let me share your help to close this issue.

New Post: DAAB - Bulk Update/Insert Using EL6

$
0
0
What's the best option to attain bulk Update/Insert using EL 6. We need to avoid multiple DB calls.

New Post: DAAB - Bulk Update/Insert Using EL6

$
0
0
You can use the UpdateDataSet methods to send batch operations. See Updating the Database from a DataSet from the
Developer's Guide to Microsoft Enterprise Library. You can set the batch size with the UpdateBatchSize parameter (use 0 for the max the database supports). See also Performing Batch Operations Using DataAdapters.

Another option is to use table valued parameters to pass multiple "records" to either a stored procedure or SQL Text command. See Use Table-Valued Parameters.

Actual performance will depend on the amount of data, network conditions, etc. Another non Enterprise Library solution is to use the SqlBulkCOpy.

~~
Randy Levy
entlib.support@live.com
Enterprise Library support engineer
Support How-to

New Post: Truncating flat file based on maximum log file size

$
0
0
Hi.

Thank you for Enterprise Library 5.0.

It doesn't seem that the built-in RollingFlatFileTraceListener supports the ability to truncate the log file if it exceeds a certain size, without rolling to a new file or overwriting/clearing the existing file.

Has anyone seen this done before?

Is it even possible to do this using a custom trace listener?

Thank you.

New Post: Appending content in block blob

$
0
0
I have created these two method in azure custom sink for semantic logging.

used azure sdk 2.0

Code for Adding content to azure block blob

private void Post(EventEntry entry, string content)
    {
        List<string> blockIds = new List<string>();
        // Retrieve storage account from connection string.
        CloudStorageAccount storageAccount = CloudStorageAccount.Parse(ConnectionString);

        // Create the blob client.
        CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();

        // Retrieve reference to a previously created container.
        CloudBlobContainer container = blobClient.GetContainerReference(ContainerName);


        // Create the container if it doesn't already exist.
        container.CreateIfNotExists();


        string fileName = DateTime.Now.ToShortDateString();

        CloudBlockBlob blockBlob = container.GetBlockBlobReference(string.Format("{0}_{1}", ContainerName, fileName));

        if (!blockBlob.Exists())
        {
            var bytesToUpload = Encoding.UTF8.GetBytes(content);

            using (var ms = new MemoryStream(bytesToUpload))
            {
                blockBlob.UploadFromStream(ms);
            }
        }
        else
        {
            blockBlob.AppendText(content);
        }
    }
}

Code for appending content to azure blob

public static void AppendText(this CloudBlockBlob blob, string text)
    {

        var bytesToUpload = Encoding.UTF8.GetBytes(text);

        List<string> blockIds = new List<string>();

        if (blob.Exists())
        {
            blockIds.AddRange(blob.DownloadBlockList(BlockListingFilter.Committed).Select(b => b.Name));

            var newId = Convert.ToBase64String(Encoding.Default.GetBytes(blockIds.Count.ToString()));


            blob.PutBlock(newId, new MemoryStream(bytesToUpload), null);

            blockIds.Add(newId);

            blob.PutBlockList(blockIds);
        }
    }


I have created two method for writing content to azure blob and append content to same blob.

This was working fine for some time. It is some time keep giving
  • web proxy authentication issue
    and
  • StorageClientException - The specified block list is invalid.
What is the best solution to fix this azure source code issue. kindly help.

New Post: SLAB logging to Windows EventLog

$
0
0
I apologize for taking the discussion in a slightly different direction (EventViewer) than intended.

I am so happy to have the conversation. We need to kill in-proc logging, put a silver stake in it's heart and let the sun beam down on nearly-free (from a performance perspective) logging. I don't mean SLAB in-proc so much, because it is at least a path out of the dungeon of in-proc logging.

It's great Randy has the SLAB perspective. Coming from raw EventSource, it took me a while to warm up to it, but it seems an awesome on-ramp to EventSource.

The System/Microsoft namespace issue is partially a matter of historic timing. System because it was desired on every box, and that's where "real" CLR stuff went. Then it was the first piece of the CLR for out-of-band releases - particularly around manifests.

This is important:

"Yes, I, too, appreciate the discussion. :D FWIW, I've been spending the entire week refreshing my knowledge about logging/SLAB and learning more about ETW. It has been very involved... and I can see why developers choose Log4Net over this."

What could have made it easier? Where were the pain points? Log4Net can block, badly block, scalability (or be forever turned off :( ). Is the problem more on the app side, the creation of all those semantic methods, or consuming the trace? Something else?

New Post: SLAB logging to Windows EventLog

$
0
0
KathleenDollard wrote:
I apologize for taking the discussion in a slightly different direction (EventViewer) than intended.
No worries! We've all been there. :)
What could have made it easier? Where were the pain points? Log4Net can block, badly block, scalability (or be forever turned off :( ). Is the problem more on the app side, the creation of all those semantic methods, or consuming the trace? Something else?
Personally, I've had my nose in EntLib since about v3 or v4... so about 5-6 years now? So all my training/knowledge is around the Logging Application Block. So it has taken some time to see how SLAB works. That actually didn't take too long, as I did a lot of that last year when it first came out. Although, it does appear I got it completely wrong and am now taking a more comprehensive approach.

I think where most of the friction is coming from is what you mention earlier with history. There is a LOT of history with ETW, and it just now reaching managed code, and apparently not very well. So there's that, learning about the history of ETW, and more importantly how to utilize it in a end-to-end scenario. There's just a lot to absorb with all the blog posts and documentation to learn what is what, which is to be expected for enterprise-based scenarios (and what scares a lot of the developers away).

So there's the history, but also the components to consume/analyze the data. PerfMonitor (not to be confused with PerfMon, sigh), and PerfView. Plus EventRegister and MDT's (Microsoft.Diagnostics.Tracing) implementation of it. Then there's little things like the "mf" and "rf" parameters in wevtutil that aren't even documented anywhere (if you know what these are that would be very helpful). Also, learning the difference between SDT and MDT has been very time-consuming, as well.

Additionally, I have also spent a good deal of time with EventSourceProxy (ESP), which is an outstanding project and really the way ETW should be implemented. There really isn't an EventSource; it's just interfaces. Interfaces are be the schema definitions, and you can use metadata/fluentapi/configuration to define them. This gets rid of the Event Source Analyzer altogether and really simplifies implementation.

All of that said, I am on-board with ETW and see the value of it. Although, with the recent push for cross-platform awesomeness, that adds another layer of investigation. Personally, I am building a Xamarin.Forms framework, so I need a logging/instrumentation solution that caters to both native and cross-platform code. That currently has me angling a solution that uses ETW for service-side applications, and Xamarin.Insights for client-side applications (and maybe falling back on ETW for clients that are running on native platforms such as WPF).

Hope this helps!

New Post: MSMQ TraceListener and WCF MSMQIntegrationBinding Problem

$
0
0
Any sample console applications (Client and Server) for testing issues about MSMQ private queues ?

Console application in Client to send message and read message from/to private queue in Server.

Console application in Server to send message and read message from/toprivate queue.


Client send Message A to private Queue in Server

Server read Message A from private queue

Server sendMessage B to private queue

Client read Message B from private queue.


Client logging to MSMQ, private queue in Server.

any full source code sample in github?

New Post: SLAB logging to Windows EventLog

$
0
0
OK, I have created (yet another) unofficial package for SLAB, compiled against the MDT (Microsoft.Diagnostics.Tracing) assembly. I've called this version EnterpriseLibrary.SemanticLogging.Futures and have deployed it here:

https://www.nuget.org/packages/EnterpriseLibrary.SemanticLogging.Futures/2.0.1406.1

A couple notes around this:
  1. Compiling around the latest code in SLAB and the last stable release of MDT caused one more test to fail. I have placed this test (when_inspecting_event_with_less_writeEvent_arguments) in the EVENT_SOURCE_PACKAGE ifdef condition.
  2. I tried peeking ahead with the latest beta of MDT, and I am very sorry I did. The last release was on Halloween, and it is appropriate due to how spooky it is. :P Essentially, EventSource.CurrentThreadActivityId has been deprecated (with a thrown exception) and is failing a bunch of tests in SLAB when paired with that release now. This will take some careful coordination to get this resolved.
  3. I have also made Microsoft and patterns-and-practices owners so they can upload to this location with an official version at a later date, if they so feel inclined.
  4. I have also made a Pull Request with my additions to make this all work. You can find that here: https://slab.codeplex.com/SourceControl/network/forks/MichaelDBang/SLAB/contribution/7751 -- It looks like I need to sign a CLA to be considered for this. I doubt the EntLib team would be interested in this PR, but if so, I will go down the road of getting a signed CLA for you. :)
Anyways, hope this helps someone, and/or provides some ideas/direction for fixing this very ugly problem/mess. :P

New Post: Choose enabled categories by thread without affect others

$
0
0
Hi Guys,

Could you please help me in one stuff?

In EntLib 5, How can I Choose enabled categories by thread without affect others?

For instance:
FIRST THREAD - Enable Verbose and Error categories
SECOND THREAD - Enable Verbose category
THIRD THREAD - Enable Error category

The problem was I tried edit in runtime the TraceSources Object by removing/creating categories per thread but, of course, I was affecting other threads behavior.

Do you have any suggestion so that workaround this issue?

I appreciate your support!

Best Regards,
Anderson

New Post: Choose enabled categories by thread without affect others

$
0
0
As you found out, in general there is really just one configuration that is used the block. The usual approach for separate logging behavior per thread is to programmatically configure a separate LogWriter for each thread. This will work for thread-safe trace listeners (e.g. EventLog, database) or if writing to file based trace listeners where each thread writes to a separate log file.

Can you expand on the specifics of the behavior you wish to see?

~~
Randy Levy
entlib.support@live.com
Enterprise Library support engineer
Support How-to

New Post: Using Oracle db with Entlib

$
0
0
Hi Randy,
Thanks for help.

Do you have some sample code example for same? If yes, could you please share.
Also as you mention that refcursors have to be named as "cur_Out" so what if we have stored procedure already written and we can't change them.

Thanks in advance!
Viewing all 1928 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>